ajwang / groovypptest

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

Compiler crash with an NPE with code using @Trait with an init block #261

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The compiler crashes with an unhandled NPE in compiling the following piece of 
code
-----------------------------------------------------
@Trait class T {
    {println a}
    Integer a = 1
}

class C implements T {
    Integer getA(){
        2
    }
}
-----------------------------------------------------

Original issue reported on code.google.com by roshanda...@gmail.com on 19 Jul 2010 at 9:49

GoogleCodeExporter commented 8 years ago
A smaller snippet also makes the compiler crash with NPE but at a different 
place (going by the stacktrace)

-------------------------------
@Trait class T {
    {println 1}
}
-------------------------------

Original comment by roshanda...@gmail.com on 19 Jul 2010 at 10:03

GoogleCodeExporter commented 8 years ago
I think instance initializers don't make sense for traits either, it's in line 
with no constructors for traits.

Original comment by eugene.v...@gmail.com on 19 Jul 2010 at 10:58

GoogleCodeExporter commented 8 years ago
I agree. 

They are the same thing and if g++ decides not to support instance constructors 
in trait classes, then the fix should ensure that both (constructor and 
instance init blocks) are rejected by g++.

Original comment by roshanda...@gmail.com on 19 Jul 2010 at 11:03

GoogleCodeExporter commented 8 years ago

Original comment by eugene.v...@gmail.com on 19 Jul 2010 at 11:24

GoogleCodeExporter commented 8 years ago

Original comment by eugene.v...@gmail.com on 19 Jul 2010 at 11:38