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/11/03 16:01:00 UTC
[jira] [Updated] (GROOVY-10343) STC fails to infer dependent type
variable
[ https://issues.apache.org/jira/browse/GROOVY-10343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thodoris Sotiropoulos updated GROOVY-10343:
-------------------------------------------
Description:
I have the following program
{code:java}
class A<T1, T2 extends T1> {
T1 f;
A(T1 f) {
this.f = f;
}
T2 foo() { return null; }
}
class Test {
void test() {
Integer x = 1;
var y = new A<>(x).foo();
Integer z = y;
}
}
{code}
h3. Actual behavior
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 14: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Integer
@ line 14, column 17.
Integer z = y;
^
1 error
{code}
h3. Expected behaviour
Compile successfully
Note that the program above compiles as expected in javac.
Tested against master (https://github.com/apache/groovy/commit/cee45d768bb65d1254a61a6dd4ce3c6a1f2ee3ca)
was:
I have the following program
{code:java}
class A<T1, T2 extends T1> {
T1 f;
A(T1 f) {
this.f = f;
}
T2 foo() { return null; }
}
class Test {
void test() {
Integer x = 1;
var y = new A<>(x).foo();
Integer z = y;
}
}
{code}
h3. Actual behavior
{code}
{code}
> STC fails to infer dependent type variable
> ------------------------------------------
>
> Key: GROOVY-10343
> URL: https://issues.apache.org/jira/browse/GROOVY-10343
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Priority: Major
>
> I have the following program
> {code:java}
> class A<T1, T2 extends T1> {
> T1 f;
> A(T1 f) {
> this.f = f;
> }
> T2 foo() { return null; }
> }
> class Test {
> void test() {
> Integer x = 1;
> var y = new A<>(x).foo();
> Integer z = y;
> }
>
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 14: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Integer
> @ line 14, column 17.
> Integer z = y;
> ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> Note that the program above compiles as expected in javac.
> Tested against master (https://github.com/apache/groovy/commit/cee45d768bb65d1254a61a6dd4ce3c6a1f2ee3ca)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)