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

Compiler Errors for @Immutable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.8, 1.7.10, 1.8.0
    • 1.8.1
    • None
    • None
    • Mac OS X

    Description

      @Immutable
      class X {
        int a	
      }
      

      Leads to (groovy 1.7.10, executed using gradle)

      java.lang.RuntimeException: Explicit constructors not allowed for @Immutable class: X
      	at org.codehaus.groovy.transform.ImmutableASTTransformation.createConstructor(ImmutableASTTransformation.java:308)
      	at org.codehaus.groovy.transform.ImmutableASTTransformation.visit(ImmutableASTTransformation.java:117)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:129)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:172)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:942)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:497)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:474)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:453)
      	at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:67)
      	at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:180)
      	at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:148)
      	at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:162)
      
      @Immutable
      class X {
      }
      

      Leads to (groovy 1.7.8.xx-20110426-1500-e36, eclipse)

      Duplicate method X() in type X
      
      class Y {
        X x
      }
      

      Leads to (groovy 1.7.8.xx-20110426-1500-e36, eclipse)

      General error during canonicalization: @Immutable processor doesn't know how to handle field 'x' of type 'playground.X' while compiling class playground.Y.
      @Immutable classes currently only support properties with known immutable types or types where special handling achieves immutable behavior, including:
      - Strings, primitive types, wrapper types, BigInteger and BigDecimal, enums
      - other @Immutable classes and known immutables (java.awt.Color, java.net.URI)
      - Cloneable classes, collections, maps and arrays, and other classes with special handling (java.util.Date)
      Other restrictions apply, please see the groovydoc for @Immutable for further details
      

      Attachments

        Activity

          People

            paulk Paul King
            peter.rietzler@smarter-ecommerce.com Peter Rietzler
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: