You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/02/24 18:58:00 UTC
[jira] [Created] (GROOVY-9953) Type from flow typing is not
propagated in variable assignments
Stefanos Chaliasos created GROOVY-9953:
------------------------------------------
Summary: Type from flow typing is not propagated in variable assignments
Key: GROOVY-9953
URL: https://issues.apache.org/jira/browse/GROOVY-9953
Project: Groovy
Issue Type: Bug
Components: Static compilation, Static Type Checker
Affects Versions: 4.0.0-alpha-2, 3.0.7
Reporter: Stefanos Chaliasos
I have the following Groovy program.
{code:groovy}
class A {}
@groovy.transform.CompileStatic
class Main {
static A bar(Object x) {
if (x instanceof A) {
def y = x // Inferred Object and not A
y
} else {
new A()
}
}
}
{code}
h2. Actual Behavior
The program does not compile, and I get the following error.
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 9: [Static type checking] - Cannot return value of type java.lang.Object on method returning type A
@ line 9, column 7.
y
^
1 error
{code}
h2. Expected Behavior
Compile successfully.
h2. Affected Version
I have also tested it with the compiler from Master (commit: 444f6a5e7f10b75d43d94e7bb4fe771ae384c321).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)