ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

Trivial closure example - fails to compile #406

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The following program:

@Typed(TypePolicy.STATIC)
class Test {
    static void main(String[] args)  {
        def lt = { int a, int b -> (a < b)}
        println( lt(2,3))
    }
}

Compiled and run thus:
groovy -cp gpp.jar ClosureTest.groovy

Generates this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\smendola\Home\groovy\ClosureTest.groovy: 4: A transform used a 
generics containing ClassNode groovy.lang.Closure <V extends java.lang.Object 
-> java.lang.Object> for the super class Test$main$1 directly. You are not 
suppposed to do this. Please create a new ClassNode refering to the old 
ClassNode and use the new ClassNode instead of the old one. Otherwise the 
compiler will create wrong descriptors and a potential NullPointerException in 
TypeResolver in the OpenJDK. If this is not your own doing, please report this 
bug to the writer of the transform.
 @ line 4, column 12.
                def lt = { int a, int b -> (a < b)}
              ^

1 error

Changing STATIC back to DYNAMIC, program compiles, runs, and generated expected 
output:

$ groovy -cp gpp.jar ClosureTest.groovy
true

$ groovy -version
Groovy Version: 1.8.5 JVM: 1.6.0_25 Vendor: Sun Microsystems Inc. OS: Windows 7

GPP version:
ImplementationVersion=0.9.0
BuildDate=05-Sep-2011
BuildTime=11:54 PM

If the program needs to be modified in order to be valid Groovy++ STATIC, 
that's fine (grateful if you could post corrected code). However, the compile 
time error that is shown above is inappropriate, and suggests a bug in G++, 
rather than in the program.

Original issue reported on code.google.com by smend...@gmail.com on 6 Feb 2012 at 4:05

Attachments: