[
https://issues.apache.org/jira/browse/GROOVY-10086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-10086.
------------------------------
> STC misses type error when calling a vararg method
> --------------------------------------------------
>
> Key: GROOVY-10086
> URL: https://issues.apache.org/jira/browse/GROOVY-10086
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-beta-1
>
>
> I have the following program
>
> {code:java}
> class Foo {}
> class X<T> {
> T f;
> X(T f) {
> this.f = f;
> }
> T getF() {
> this.f;
> }
> }
> class A {
> void foo(int x, X<Foo>... y) {
> Foo foo = y[0].getF(); // ClastCastException at runtime
> }
> }
> public class Main {
> public static void main(String[] args) {
> A a = new A();
> a.foo(1, new X<>(1));
> }
> }
> {code}
> h3. Actual Behaviour
> groovyc compiles this program, but we get the following exception at runtime
> {code:java}
> Exception in thread "main"
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
> object '1' with class 'java.lang.Integer' to class 'Foo'
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:415)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:329)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:243)
> at
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
> at A.foo(test.groovy:16)
> at Main.main(test.groovy:23)
> {code}
> h3. Expected Behaviour
> groovyc should have rejected this program with an error similar to the
> following
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> test.groovy: 23: [Static type checking] - Cannot call A#foo(int, X<Foo>[])
> with arguments [int, X<java.lang.Integer>]
> @ line 23, column 7.
> a.foo(1, new X<>(1));
> ^1 error
> {code}
> Tested against master
> ([https://github.com/apache/groovy/commit/2df019d3c93486e8a32d407d364913e7b65e1cba])
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)