_Migrated from Google Code (issue 586)_
:bust_in_silhouette: jrdalpra :clock8: Oct 08, 2013 at 20:34 UTC
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The compilation throws an error: call to super not allowed in enum constructor
What version of the product are you using? On what operating system?
0.12.0 at Windows and oracle javac compiler
Please provide any additional information below.
Example of a enum that matches the case above explained.
@ Getter
@ RequiredArgsConstructor
@ ExtensionMethod({ MyUtilityClassWithExtensionMethods.class })
public enum MyClass {
CONSTANT("some string info like a description") {
@ Override
public boolean method(String value) {
// using the attribute
System.out.println(getAttributeToBeInitialized().someExtensionMethod());
// the error occurs even if you do not use the extension method
return true;
}
};
final String attributeToBeInitialized;
public boolean method(String value) {
return false;
}
}
public class MyUtilityClassWithExtensionMethods {
public static String someExtensionMethod(String string) {
return string;
}
}
Thanks.
:bust_in_silhouette: reinierz :clock8: Oct 10, 2013 at 21:03 UTC
Thanks for finding this; we call attribution for @ ExtensionMethod and a few other things; this adds implicit super() calls all over the place (it's hard to find out which source is exactly affected, unfortunately, it's not just the code we attribute, it also happens to code referenced by the code we attribute). We thought it didn't matter much (other than generate extra lines in delombok, where we just remove all super() calls), but it turns out it matters here.
Fixing this is going to be extremely difficult, unfortunately. Awesome find, though :)
NB: For future volunteers: The key aspects are @ ExtensionMethod, a 'complex' enum value (with its own block; attributing this vardecl is what generates the superfluous super() call), and at least 1 method call, to anything, in that block, to trigger attribution to check if @ ExtensionMethod needs to go to work. It doesn't have to be an actual extensionmethod call, even System.out.println(); will do.
:bust_in_silhouette: jrdalpra :clock8: Oct 11, 2013 at 00:19 UTC
Thanks for you reply
:bust_in_silhouette: askoning :clock8: Nov 11, 2013 at 10:35 UTC
This looks suspiciously much like issue #349.
:bust_in_silhouette: tom19xx :clock8: Jan 05, 2014 at 21:26 UTC
Hello,
I got the same compilation error without using the @ ExtensionMethod annotation.
I stripped down to implementation to the following code where the combination of overriding an abstract member function and usage of 'val' within this function seems to trigger the error.
lombok version: 0.12.0
javac version: 1.6.0_35
import lombok.val;
public enum MyEnum {
VAL1("title1") {
@ Override
public String getValue() {
// usage of 'val' here causes the compilation error
val s = "value1";
return s;
}
};
private final String title;
private MyEnum(String title)
{
this.title = title;
}
public abstract String getValue();
}
Btw. - many thanks to the lombok project - it's really great!
_End of migration_
Most helpful comment
:bust_in_silhouette: tom19xx :clock8: Jan 05, 2014 at 21:26 UTC
Hello,
I got the same compilation error without using the @ ExtensionMethod annotation.
I stripped down to implementation to the following code where the combination of overriding an abstract member function and usage of 'val' within this function seems to trigger the error.
lombok version: 0.12.0
javac version: 1.6.0_35
import lombok.val;
public enum MyEnum {
VAL1("title1") {
@ Override
public String getValue() {
// usage of 'val' here causes the compilation error
val s = "value1";
return s;
}
};
private final String title;
private MyEnum(String title)
{
this.title = title;
}
public abstract String getValue();
}
Btw. - many thanks to the lombok project - it's really great!