[
https://issues.apache.org/jira/browse/GROOVY-6837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17474647#comment-17474647
]
Eric Milles commented on GROOVY-6837:
-------------------------------------
For (1) "words = words + nums", there are two steps, first an Object[] is
created like in case (1) then the assignment of Object[] to String[] runs
through DefaultTypeTransformation#castToType. This second step is where you
get strings '5' and '10' in the result. If
{{DefaultGroovyMethods#plus(T[],T[])}} is altered not to produce an Object[]
internally, is the expectation still that numbers are converted to strings?
I think the Java inference engine has a different type for T for a call
"String[] x; Integer[] y; plus(x,y);". I was pondering this when looking over
the plus methods. I'm not sure there is a type-safe way to provide "def <T>
T[] plus(T[] a, T[] b)". The second array may need to be Object[] so that T
remains set by the first argument (left operand in "a+b").
> String[] + String[] gives Object[]
> ----------------------------------
>
> Key: GROOVY-6837
> URL: https://issues.apache.org/jira/browse/GROOVY-6837
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.3.1
> Reporter: Dmitry Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> {code:java}
> def a1 = ["a", "b"] as String[], a2 = ["c", "d"] as String[];
> def concatenated = a1 + a2;
> java.nio.file.Paths.get("parent", concatenated)
> {code}
> ==>
> {noformat}
> groovy.lang.MissingMethodException: No signature of method: static
> java.nio.file.Paths.get() is applicable for argument types:
> (java.lang.String, [Ljava.lang.Object;) values: [parent, [a, b, c, d]]
> Possible solutions: get(java.lang.String, [Ljava.lang.String;),
> get(java.net.URI), grep(), getAt(java.lang.String), wait(), any()
> at
> groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1373)
> at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1359)
> at
> org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
> at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
> at ideaGroovyConsole.run(ideaGroovyConsole.groovy:4)
> at
> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:258)
> at groovy.lang.GroovyShell.run(GroovyShell.java:502)
> at groovy.lang.GroovyShell.run(GroovyShell.java:481)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:166)
> at
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:68)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
> at console.run(console.txt:25)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)