groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chaitanya Birudavolu (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8952) Eager interpolation evaluating as a Closure does a lazy invoke of the Closure
Date Tue, 08 Jan 2019 08:43:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8952?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Chaitanya Birudavolu updated GROOVY-8952:
-----------------------------------------
    Description: 
This is regarding the eager interpolation placeholder
{code:java}
${ <expression> }{code}
The expected behavior is that the expression would be evaluated eagerly (at GString creation
time). Later, at GString coercion time, the value that is expected in the place of the eager
placeholder is the result of
{code:java}
<expression>.toString(){code}
 

 

This works most of the time, but doesn't seem to work if the expression evaluates to a Closure
type. If the expression evaluates to a Closure type, what is observed is that, in the place
of the placeholder, instead of seeing ...
{code:java}
<closure>.toString(){code}
... we see...
{code:java}
<closure-invocation-result>.toString(){code}
For example, in the below code...

 
{code:java}
def c = {->println ('Inside closure')}
println ('Just before creating the GString')
def gstr = "${println ('Inside eager placeholder'); 20; 30; c}"
println ('Just after creating the GString')
println (gstr)
{code}
 

...the expected behavior is that the closure should never get executed, and the last println
should only print the result of
{code:java}
c.toString(){code}
Instead, the last line printed is observed to be:
{code:java}
Inside closure{code}
 

  was:
This is regarding the eager placeholder
{code:java}
${ <expression> }{code}
The expected behavior is that the expression would be evaluated eagerly (at GString creation
time). Later, at GString coercion time, the value that is expected in the place of the eager
placeholder is the result of
{code:java}
<expression>.toString(){code}
 

 

This works most of the time, but doesn't seem to work if the expression evaluates to a Closure
type. If the expression evaluates to a Closure type, what is observed is that, in the place
of the placeholder, instead of seeing ...
{code:java}
<closure>.toString(){code}
... we see...
{code:java}
<closure-invocation-result>.toString(){code}
For example, in the below code...

 
{code:java}
def c = {->println ('Inside closure')}
println ('Just before creating the GString')
def gstr = "${println ('Inside eager placeholder'); 20; 30; c}"
println ('Just after creating the GString')
println (gstr)
{code}
 

...the expected behavior is that the closure should never get executed, and the last println
should only print the result of
{code:java}
c.toString(){code}
Instead, the last line printed is observed to be:
{code:java}
Inside closure{code}
 


> Eager interpolation evaluating as a Closure does a lazy invoke of the Closure
> -----------------------------------------------------------------------------
>
>                 Key: GROOVY-8952
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8952
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.5
>         Environment: Windows 10
>            Reporter: Chaitanya Birudavolu
>            Priority: Major
>              Labels: closure, eager, interpolation
>
> This is regarding the eager interpolation placeholder
> {code:java}
> ${ <expression> }{code}
> The expected behavior is that the expression would be evaluated eagerly (at GString
creation time). Later, at GString coercion time, the value that is expected in the place
of the eager placeholder is the result of
> {code:java}
> <expression>.toString(){code}
>  
>  
> This works most of the time, but doesn't seem to work if the expression evaluates to
a Closure type. If the expression evaluates to a Closure type, what is observed is that, in
the place of the placeholder, instead of seeing ...
> {code:java}
> <closure>.toString(){code}
> ... we see...
> {code:java}
> <closure-invocation-result>.toString(){code}
> For example, in the below code...
>  
> {code:java}
> def c = {->println ('Inside closure')}
> println ('Just before creating the GString')
> def gstr = "${println ('Inside eager placeholder'); 20; 30; c}"
> println ('Just after creating the GString')
> println (gstr)
> {code}
>  
> ...the expected behavior is that the closure should never get executed, and the last
println should only print the result of
> {code:java}
> c.toString(){code}
> Instead, the last line printed is observed to be:
> {code:java}
> Inside closure{code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message