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

Calling super in an overridden method results in MissingMethodException when method indirectly inherited from trait

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.15
    • 5.0.0-alpha-2
    • None

    Description

      Consider the following:

      trait A {
          void doSomething() {
              println "A"
          }
      }
      
      trait B extends A {}
      
      class C implements B {
          @Override
          void doSomething() {
              B.super.doSomething()
          }
      
          static void main(String[] args) {
              new C().doSomething()
          }
      }
      

      Although this compiles fine, a MissingMethodException is thrown at runtime:

      Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static B.doSomething() is applicable for argument types: (C) values: [C@12f41634]
      	at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)
      	at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)
      	at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:921)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)
      	at B$Trait$Helper.$static_methodMissing(Bug.groovy)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      	at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1516)
      	at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)
      	at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
      	at C.doSomething(Bug.groovy:12)
      	at A$doSomething.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      	at C.main(Bug.groovy:16)
      

      There appears to be no way to override a method from a trait that was implemented in a "supertrait" and delegate to the original implementation.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jcttrll Jonathan Cottrill
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: