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/10 13:23:00 UTC

[jira] [Created] (GROOVY-10360) STC ignores declared type of variable

Thodoris Sotiropoulos created GROOVY-10360:
----------------------------------------------

             Summary: STC ignores declared type of variable
                 Key: GROOVY-10360
                 URL: https://issues.apache.org/jira/browse/GROOVY-10360
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I don't know if this is a bug or an expected behaviour, but in the following example, groovyc ignores the declared type of variable `x`.

{code:java}
class A {
  void m() {}
}

class Test {
  public static void main(String[] args) {
    final Object x = foo();
    x.m(); // should report an error. method `m` is not found in class Object.
  }

  public static A foo() {
    return new A();
  }
}
{code}

h3. Actual behaviour

groovyc compiles this program

h3. Expected behaviour

groovyc should reject this program with an error of the form

{code}
Cannot find method Object#m()
{code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)