8235778: No compilation error reported when a record is declared in a local class
Reviewed-by: mcimadamore
This commit is contained in:
parent
1b4b652408
commit
89e0d29101
@ -1207,6 +1207,9 @@ public class Check {
|
|||||||
mask = (flags & RECORD) != 0 ? LocalRecordFlags : LocalClassFlags;
|
mask = (flags & RECORD) != 0 ? LocalRecordFlags : LocalClassFlags;
|
||||||
if ((flags & RECORD) != 0) {
|
if ((flags & RECORD) != 0) {
|
||||||
implicit = STATIC;
|
implicit = STATIC;
|
||||||
|
if (sym.owner.kind == TYP) {
|
||||||
|
log.error(pos, Errors.RecordDeclarationNotAllowedInInnerClasses);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((sym.owner.flags_field & STATIC) == 0 &&
|
if ((sym.owner.flags_field & STATIC) == 0 &&
|
||||||
(flags & ENUM) != 0) {
|
(flags & ENUM) != 0) {
|
||||||
|
@ -383,6 +383,14 @@ public class RecordCompilationTests extends CompilationTestCase {
|
|||||||
" record RR(int x) { public int x() { return y; }};\n" +
|
" record RR(int x) { public int x() { return y; }};\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}");
|
"}");
|
||||||
|
// can be contained inside a lambda
|
||||||
|
assertOK("""
|
||||||
|
class Outer {
|
||||||
|
Runnable run = () -> {
|
||||||
|
record TestRecord(int i) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
|
||||||
// Can't self-shadow
|
// Can't self-shadow
|
||||||
assertFail("compiler.err.already.defined",
|
assertFail("compiler.err.already.defined",
|
||||||
@ -431,5 +439,34 @@ public class RecordCompilationTests extends CompilationTestCase {
|
|||||||
" record R(int a) {}\n" +
|
" record R(int a) {}\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}");
|
"}");
|
||||||
|
assertFail("compiler.err.record.declaration.not.allowed.in.inner.classes",
|
||||||
|
"""
|
||||||
|
class Outer {
|
||||||
|
public void test() {
|
||||||
|
class Inner extends Outer {
|
||||||
|
record R(int i) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
assertFail("compiler.err.record.declaration.not.allowed.in.inner.classes",
|
||||||
|
"""
|
||||||
|
class Outer {
|
||||||
|
Runnable run = new Runnable() {
|
||||||
|
record TestRecord(int i) {}
|
||||||
|
public void run() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
assertFail("compiler.err.record.declaration.not.allowed.in.inner.classes",
|
||||||
|
"""
|
||||||
|
class Outer {
|
||||||
|
void m() {
|
||||||
|
record A() {
|
||||||
|
record B() { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user