Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246199: 'permits' is a restricted identifier
Reviewed-by: mcimadamore
  • Loading branch information
Vicente Romero committed Jun 8, 2020
1 parent 358714b commit e90621c1692dfc6ebf7c506f27b978bbaee9e2e9
@@ -3360,6 +3360,13 @@ Source restrictedTypeNameStartingAtSource(Name name, int pos, boolean shouldWarn
log.warning(pos, Warnings.RestrictedTypeNotAllowedPreview(name, Source.JDK15));
}
}
if (name == names.permits) {
if (allowSealedTypes) {
return Source.JDK15;
} else if (shouldWarn) {
log.warning(pos, Warnings.RestrictedTypeNotAllowedPreview(name, Source.JDK15));
}
}
return null;
}

@@ -267,6 +267,8 @@ public void testRestrictedKeyword() {

for (String s : List.of(
"class sealed {}",
"enum sealed {}",
"record sealed() {}",
"interface sealed {}",
"@interface sealed {}"
)) {
@@ -281,6 +283,34 @@ public void testRestrictedKeyword() {
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) { } }",
"class SealedTest { void permits(String permits) { } }",
"class SealedTest { void test() { String permits = null; } }"
)) {
assertOK(s);
}

for (String s : List.of(
"class permits {}",
"enum permits {}",
"record permits() {}",
"interface permits {}",
"@interface permits {}"
)) {
assertFail("compiler.err.restricted.type.not.allowed", s);
}

for (String s : List.of(
"class Foo { permits m() {} }",
"class Foo { permits i; }",
"class Foo { void m(permits i) {} }"
)) {
assertFail("compiler.err.restricted.type.not.allowed.here", s);
}

String[] testOptions = {/* no options */};
String[] previousCompOptions = getCompileOptions();
setCompileOptions(testOptions);

0 comments on commit e90621c

Please sign in to comment.