-
-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: records can have static initializers #4962
fix: records can have static initializers #4962
Conversation
void testBuildRecordModelWithStaticInitializer() { | ||
// contract: a record can have static initializers | ||
String code = "src/test/resources/records/WithStaticInitializer.java"; | ||
CtModel model = assertDoesNotThrow(() -> createModelFromPath(code)); | ||
List<CtAnonymousExecutable> execs = model.getElements(new TypeFilter<>(CtAnonymousExecutable.class)); | ||
assertThat(execs.size(), equalTo(2)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use ModelTest
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As building the model failed, we can't use ModelTest here
if (member instanceof CtAnonymousExecutable) { | ||
JLSViolation.throwIfSyntaxErrorsAreNotIgnored(this, "Anonymous executable is not allowed in a record"); | ||
if (member instanceof CtAnonymousExecutable && !member.isStatic()) { | ||
JLSViolation.throwIfSyntaxErrorsAreNotIgnored(this, "Instance initializer is not allowed in a record"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An oversight from myself earlier, we should add the JLS paragraph here. Could you add it?
Impressive high speed at fixing issues, thank @SirYwell. Will merge later today/tomorrow after the 24-hour period. If I forgot to merge it, feel free to ping me. |
Fixes #4961
While instance initializers are forbidden, static initializers are allowed.