Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gjoseph
Created January 5, 2012 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjoseph/1565938 to your computer and use it in GitHub Desktop.
Save gjoseph/1565938 to your computer and use it in GitHub Desktop.
Did i just find a bug in @canonical or am i thick ? #groovy
#!/usr/bin/env groovy
import groovy.transform.Canonical
def weird = new CanonicalIsWeird(a: 'first letter', b: 'second letter')
println "a: ${weird.a}"
println "b: ${weird.b}"
assert weird.a == 'first letter'
assert weird.b == 'second letter'
@Canonical
class CanonicalIsWeird {
def a, b
}
@breun
Copy link

breun commented Jan 5, 2012

I'm not sure, but it looks weird to me.

$ groovy -v
Groovy Version: 1.8.5 JVM: 1.6.0_29 Vendor: Apple Inc. OS: Mac OS X
$ ./test.groovy 
a: [a:first letter, b:second letter]
b: 
Caught: Assertion failed: 

assert weird.a == 'first letter'
       |     | |
       |     | false
       |     [a:first letter, b:second letter]
       CanonicalIsWeird([a:first letter, b:second letter], )

Assertion failed: 

assert weird.a == 'first letter'
       |     | |
       |     | false
       |     [a:first letter, b:second letter]
       CanonicalIsWeird([a:first letter, b:second letter], )

        at test.run(test.groovy:9)```

@gjoseph
Copy link
Author

gjoseph commented Jan 5, 2012

Indeed. I was expecting both assertions to pass.

@paulk-asert
Copy link

Can you raise a Jira please. The workaround is to give types to your properties, e.g. String in this case - for at least the first property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment