Re: safe call evaluates arguments first?
Jochen Theodorou <[email protected]> Fri, 28 Mar 2025 17:26:34 +0100
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <[email protected]> |
please add an issue On 3/28/25 00:10, OCsite wrote: > Thanks! > > Should I add a jira? Or will you? Or not worth one? > > All the best, > OC > >> On 27. 3. 2025, at 21:28, Jochen Theodorou <[email protected]> wrote: >> >> On 27.03.25 18:11, [email protected] wrote: >>> Hi there, >>> >>> I've just bumped into this behaviour, as shown e.g., by the code quoted below. A safe method call first evaluates method's arguments, and only then trashes the call. >> >> I think we do in general: >> * push arguments on stack >> * push receiver on stack >> * write method call >> >> and for the safe variant we probably do: >> * 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 >> >>> Is this the intended behaviour? 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) — but perhaps I am overlooking something of importance. >> >> expected yes... correct is the other question, because I am with you, >> this should be like the if-variant >> >> bye Jochen >> >