You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2024/05/18 14:54:00 UTC
[jira] [Created] (GROOVY-11381) STC: field and interface default method accessor
Eric Milles created GROOVY-11381:
------------------------------------
Summary: STC: field and interface default method accessor
Key: GROOVY-11381
URL: https://issues.apache.org/jira/browse/GROOVY-11381
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Eric Milles
Consider the following:
{code:java}
package p;
public interface I {
default Number getFoo() { return 42; }
}
{code}
{code:groovy}
class C implements p.I {
private String foo
}
@groovy.transform.CompileStatic
void test(C c) {
def foo = c.foo
print foo
}
test(new C())
{code}
This script prints "42" but the inferred type of "c.foo" is String. Changing "def" to "Number" results in: Cannot assign value of type java.lang.String to variable of type java.lang.Number
--
This message was sent by Atlassian Jira
(v8.20.10#820010)