ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

Comparing String and GStringImpl fails #400

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This snippet reproduces the problem:

n = 42
@Typed eq(x, y) { x == y }
assert '42' == "$n"
assert "$n" == '42'
assert eq('42', "$n") // -> fails
assert eq("$n", '42') // -> fails

Using the featured download of groovypp-0.9.0 with groovy-1.8.2

Original issue reported on code.google.com by a...@schmideg.net on 13 Oct 2011 at 4:16

GoogleCodeExporter commented 8 years ago
type cast via
@Typed eq(String x, y) { x==y}

You could also use overload mechanism :
​n = 42 
@Typed eq(String x, GString y) { println "String / GString"; x==y}
@Typed eq(GString x, String y) { println "GString / String"; x==y}
@Typed eq(String x, String y) { println "String / String"; x==y}

assert '42' == "$n" 
assert "$n" == '42' 
assert eq('42', "$n") // -> OK 
assert eq("$n", '42') // -> OK
assert eq("$n".toString(), '42') // -> OK
println ("finished")​

Imho it's useless to  annotate @typed without using types. 

Original comment by gabriel....@googlemail.com on 18 Oct 2011 at 7:47