8259905: Compiler treats 'sealed' keyword as 'var' keyword
Reviewed-by: jlahoda
This commit is contained in:
parent
6415d3b82b
commit
b2e582a882
@ -3338,13 +3338,15 @@ public class JavacParser implements Parser {
|
||||
if (elemType.hasTag(IDENT)) {
|
||||
Name typeName = ((JCIdent)elemType).name;
|
||||
if (restrictedTypeNameStartingAtSource(typeName, pos, !compound && localDecl) != null) {
|
||||
if (type.hasTag(TYPEARRAY) && !compound) {
|
||||
if (typeName != names.var) {
|
||||
reportSyntaxError(elemType.pos, Errors.RestrictedTypeNotAllowedHere(typeName));
|
||||
} else if (type.hasTag(TYPEARRAY) && !compound) {
|
||||
//error - 'var' and arrays
|
||||
reportSyntaxError(pos, Errors.RestrictedTypeNotAllowedArray(typeName));
|
||||
reportSyntaxError(elemType.pos, Errors.RestrictedTypeNotAllowedArray(typeName));
|
||||
} else {
|
||||
if(compound)
|
||||
//error - 'var' in compound local var decl
|
||||
reportSyntaxError(pos, Errors.RestrictedTypeNotAllowedCompound(typeName));
|
||||
reportSyntaxError(elemType.pos, Errors.RestrictedTypeNotAllowedCompound(typeName));
|
||||
startPos = TreeInfo.getStartPos(mods);
|
||||
if (startPos == Position.NOPOS)
|
||||
startPos = TreeInfo.getStartPos(type);
|
||||
|
@ -5,13 +5,13 @@ ParserTest.java:24:14: compiler.err.restricted.type.not.allowed: var, 10
|
||||
ParserTest.java:28:20: compiler.err.restricted.type.not.allowed: var, 10
|
||||
ParserTest.java:36:27: compiler.err.restricted.type.not.allowed: var, 10
|
||||
ParserTest.java:38:5: compiler.err.restricted.type.not.allowed.here: var
|
||||
ParserTest.java:41:15: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:42:13: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:43:17: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:44:13: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:45:15: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:46:13: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:49:24: compiler.err.restricted.type.not.allowed.compound: var
|
||||
ParserTest.java:41:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:42:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:43:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:44:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:45:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:46:9: compiler.err.restricted.type.not.allowed.array: var
|
||||
ParserTest.java:49:9: compiler.err.restricted.type.not.allowed.compound: var
|
||||
ParserTest.java:54:5: compiler.err.restricted.type.not.allowed.here: var
|
||||
ParserTest.java:58:16: compiler.err.restricted.type.not.allowed.here: var
|
||||
ParserTest.java:59:14: compiler.err.restricted.type.not.allowed.here: var
|
||||
|
@ -258,30 +258,8 @@ public class SealedCompilationTests extends CompilationTestCase {
|
||||
"class SealedTest { int sealed = 0; int non = 0; int ns = non-sealed; }",
|
||||
"class SealedTest { void test(String sealed) { } }",
|
||||
"class SealedTest { void sealed(String sealed) { } }",
|
||||
"class SealedTest { void test() { String sealed = null; } }"
|
||||
)) {
|
||||
assertOK(s);
|
||||
}
|
||||
"class SealedTest { void test() { String sealed = null; } }",
|
||||
|
||||
for (String s : List.of(
|
||||
"class sealed {}",
|
||||
"enum sealed {}",
|
||||
"record sealed() {}",
|
||||
"interface sealed {}",
|
||||
"@interface sealed {}"
|
||||
)) {
|
||||
assertFail("compiler.err.restricted.type.not.allowed", s);
|
||||
}
|
||||
|
||||
for (String s : List.of(
|
||||
"class Foo { sealed m() {} }",
|
||||
"class Foo { sealed i; }",
|
||||
"class Foo { void m(sealed i) {} }"
|
||||
)) {
|
||||
assertFail("compiler.err.restricted.type.not.allowed.here", s);
|
||||
}
|
||||
|
||||
for (String s : List.of(
|
||||
"class SealedTest { String permits; }",
|
||||
"class SealedTest { int permits = 0; }",
|
||||
"class SealedTest { void test(String permits) { } }",
|
||||
@ -292,6 +270,12 @@ public class SealedCompilationTests extends CompilationTestCase {
|
||||
}
|
||||
|
||||
for (String s : List.of(
|
||||
"class sealed {}",
|
||||
"enum sealed {}",
|
||||
"record sealed() {}",
|
||||
"interface sealed {}",
|
||||
"@interface sealed {}",
|
||||
|
||||
"class permits {}",
|
||||
"enum permits {}",
|
||||
"record permits() {}",
|
||||
@ -302,10 +286,16 @@ public class SealedCompilationTests extends CompilationTestCase {
|
||||
}
|
||||
|
||||
for (String s : List.of(
|
||||
"class Foo { sealed m() {} }",
|
||||
"class Foo { sealed i; }",
|
||||
"class Foo { void m() { sealed i; } }",
|
||||
"class Foo { void m(sealed i) {} }",
|
||||
|
||||
"class Foo { permits m() {} }",
|
||||
"class Foo { permits i; }",
|
||||
"class Foo { void m() { permits i; } }",
|
||||
"class Foo { void m(permits i) {} }"
|
||||
)) {
|
||||
)) {
|
||||
assertFail("compiler.err.restricted.type.not.allowed.here", s);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user