Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.0-beta-1, 2.3.0-beta-2
-
None
Description
Following test code:
class DynamicTraitTest extends GroovyTestCase { @groovy.transform.TypeChecked void testTraitTest() { def x = new String("hello") as Helloable x.hello() assert !(x instanceof String) assert x instanceof Helloable assert x.toUpperCase() == "HELLO" // exptected assert x.tr('h','*') == "*ello" // fails } } trait Helloable implements CharSequence { void hello() { println "hello" } }
generates following Exception.
% groovy dynamictrait2.groovy
groovy dynamictrait2.groovy
.hello
E
Time: 0.182
There was 1 error:
1) testTraitTest(DynamicTraitTest)Assertion failed:assert x.tr('h','*') == "*ello" // fails
false String1_groovyProxy@1ce24091
String1_groovyProxy@1ce24091at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:398)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:646)
at DynamicTraitTest.testTraitTest(dynamictrait2.groovy:9)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1318)
at org.codehaus.groovy.runtime.InvokerHelper.invokeStaticMethod(InvokerHelper.java:927)
at org.codehaus.groovy.runtime.InvokerHelper.invokeStaticMethod(InvokerHelper.java:77)
at groovy.lang.GroovyShell.runJUnit3Test(GroovyShell.java:353)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:273)
at groovy.lang.GroovyShell.run(GroovyShell.java:502)
at groovy.lang.GroovyShell.run(GroovyShell.java:491)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:627)
at groovy.ui.GroovyMain.run(GroovyMain.java:379)
at groovy.ui.GroovyMain.process(GroovyMain.java:365)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:124)
at groovy.ui.GroovyMain.main(GroovyMain.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
IMHO, String.tr() is a DGM method for String, so above code is expected to be succeeded same as String.toUpperCase() on the groovyProxy.