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

Problem With Compiler Error Message And Conflicting Trait Methods

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.3
    • Fix Version/s: 2.3.8
    • Component/s: Compiler
    • Labels:
      None

      Description

      SomeTrait.groovy
      trait SomeTrait {
          int getMagicNumber() {
              42
          }
      }
      
      SomeClass.groovy
      class SomeClass implements SomeTrait {
          static magicNumber = 'Forty Two'
      }
      
      $ groovyc SomeClass.groovy 
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      SomeClass.groovy: 1: Can't have an abstract method in a non-abstract class. The class 'SomeClass' must be declared abstract or the method 'int getMagicNumber()' must be implemented.
       @ line 1, column 1.
         class SomeClass implements SomeTrait {
         ^
      
      1 error
      
      trait $ groovy -version
      Groovy Version: 2.3.3 JVM: 1.7.0_45 Vendor: Oracle Corporation OS: Mac OS X
      

      If the code that adds the trait method figures out that it can't or won't add the method, it seems like the system should have enough context at that point to report why and give the user better feedback.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                melix C├ędric Champeau
                Reporter:
                brownj Jeff Brown
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: