Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10127

STC misses type check in Generic class with a bounded type parameter

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.8, 4.0.0-alpha-3
    • Fix Version/s: None
    • Labels:
      None

      Description

      I have the following Groovy program.

      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;
        }
      }
      

      Actual Behavior

      Runtime error.

      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)
      

      Expected Behavior

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

      Affected Version

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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              schaliasos Stefanos Chaliasos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: