OC created GROOVY-11591:
---------------------------

             Summary: safe call evaluates arguments 
                 Key: GROOVY-11591
                 URL: https://issues.apache.org/jira/browse/GROOVY-11591
             Project: Groovy
          Issue Type: Bug
            Reporter: OC


A safe method call first evaluates method's arguments, and only then trashes 
the call. It would seem to me much better if the arguments were not evaluated 
in this case (precisely same way as if we used the java-like  “if (obj) 
obj.whatever...” approach instead of the safe call).

Based on Jochen insight, what probably happens is

* push arguments on stack
* push receiver on stack
* write jmp if null
* write method call
* jmp to after call
* marker for null case
* remove elements from stack
* push null
* marker for after call

Testable e.g., by
{code:java}
1040 ocs /tmp> <q.groovy 
class qq {
 def foo(String s) {
   println "foo called!"
   s
 }
 def bar(String s) {
   println "bar: $s"
 }
}

null?.bar(new qq().foo('Oops!'))
1041 ocs /tmp> /usr/local/groovy-4.0.25/bin/groovy q
foo called!
1042 ocs /tmp>  {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to