Issue 400 in groovypptest: Comparing String and GStringImpl fails

12 views
Skip to first unread message

groovy...@googlecode.com

unread,
Oct 13, 2011, 12:17:05 PM10/13/11
to groovyp...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 400 by a...@schmideg.net: Comparing String and GStringImpl fails
http://code.google.com/p/groovypptest/issues/detail?id=400

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

groovy...@googlecode.com

unread,
Oct 18, 2011, 3:47:40 AM10/18/11
to groovyp...@googlegroups.com

Comment #1 on issue 400 by gabriel....@gmail.com: Comparing String and
GStringImpl fails
http://code.google.com/p/groovypptest/issues/detail?id=400

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.

Reply all
Reply to author
Forward
0 new messages