You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2021/05/13 09:26:00 UTC
[jira] [Updated] (GROOVY-10086) STC misses type error when calling
a vararg method
[ https://issues.apache.org/jira/browse/GROOVY-10086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thodoris Sotiropoulos updated GROOVY-10086:
-------------------------------------------
Description:
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])
was:
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. Actual 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)
> 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
> Priority: Major
>
> 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.3.4#803005)