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/06/08 10:07:00 UTC

[jira] [Created] (GROOVY-10127) STC misses type check in Generic class with a bounded type parameter

Stefanos Chaliasos created GROOVY-10127:
-------------------------------------------

             Summary: STC misses type check in Generic class with a bounded type parameter
                 Key: GROOVY-10127
                 URL: https://issues.apache.org/jira/browse/GROOVY-10127
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation, Static Type Checker
    Affects Versions: 4.0.0-alpha-3, 3.0.8
            Reporter: Stefanos Chaliasos


I have the following Groovy program.
{code:groovy}
public class Main {
  public static void main(String[] args) {
    new Foo<B>().foo(new B()).m()
  }
}

class A{}
class B extends A{
  void m() {}
}


@groovy.transform.TypeChecked
class Foo<T extends A> {
  T foo(T x) {
    x = new A(); // does not catch the error;
  }
}
{code}
h2. Actual Behavior

Runtime error.
{code:java}
Caught: groovy.lang.MissingMethodException: No signature of method: A.m() is applicable for argument types: () values: []
Possible solutions: is(java.lang.Object), NV([Ljava.lang.Object;), any(), dump(), any(groovy.lang.Closure), tap(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: A.m() is applicable for argument types: () values: []
Possible solutions: is(java.lang.Object), NV([Ljava.lang.Object;), any(), dump(), any(groovy.lang.Closure), tap(groovy.lang.Closure)
        at Main.main(Main.groovy:3)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
{code}
h2. Expected Behavior

groovyc should reject the program with a compile-time error.
h2. Affected Version

This programs have been tested with the compiler from the master (commit: 05a39632565bee88949c8db9d56b9f9598321fc2), 4.0.0-alpha-3, and 3.0.8.




--
This message was sent by Atlassian Jira
(v8.3.4#803005)