You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2021/11/30 22:05:00 UTC

[jira] [Comment Edited] (GROOVY-10398) LazyFieldNode never equals itself

    [ https://issues.apache.org/jira/browse/GROOVY-10398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17451375#comment-17451375 ] 

Paul King edited comment on GROOVY-10398 at 11/30/21, 10:04 PM:
----------------------------------------------------------------

For this sample here, it is the second and third false you are worried about right? Not the first?
{code:java}
import org.codehaus.groovy.ast.decompiled.LazyFieldNode
import org.codehaus.groovy.ast.FieldNode
import org.codehaus.groovy.control.CompilerConfiguration

FieldNode fn1 = FieldNode.newStatic(CompilerConfiguration, 'JDK11')
println fn1.equals(fn1) // true
FieldNode fn2 = new LazyFieldNode(() -> fn1, 'JDK11')
println fn1.equals(fn2) // false
println fn2.equals(fn1) // true
println fn2.equals(fn2) // false

List nodes1 = [fn1]
println nodes1.contains(fn1) // true
List nodes2 = [fn2]
println nodes2.contains(fn2) // false
 {code}


was (Author: paulk):
For this sample here, it is the second false you are worried about right?
{code:java}
import org.codehaus.groovy.ast.decompiled.LazyFieldNode
import org.codehaus.groovy.ast.FieldNode
import org.codehaus.groovy.control.CompilerConfiguration

FieldNode fn1 = FieldNode.newStatic(CompilerConfiguration, 'JDK11')
println fn1.equals(fn1) // true
FieldNode fn2 = new LazyFieldNode(() -> fn1, 'JDK11')
println fn1.equals(fn2) // false
println fn2.equals(fn1) // true
println fn2.equals(fn2) // false
 {code}

> LazyFieldNode never equals itself
> ---------------------------------
>
>                 Key: GROOVY-10398
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10398
>             Project: Groovy
>          Issue Type: Bug
>          Components: ast builder
>    Affects Versions: 3.0.9
>            Reporter: James Kleeh
>            Priority: Major
>
> Assume you have a LazyFieldNode instance
> LazyFieldNode node = ...
> List nodes = [node]
> `nodes.contains(node)` -> this will return false
>  
> This is because the `equals` method that `LazyFieldNode` implements compares the object to the delegate instead of itself so a lazy field node can never equal itself



--
This message was sent by Atlassian Jira
(v8.20.1#820001)