Skip to content

Commit bcb56a4

Browse files
committed
Strengthened tests and preview gating for NR1
1 parent 88b1fcd commit bcb56a4

File tree

7 files changed

+21
-29
lines changed

7 files changed

+21
-29
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class Types {
102102

103103
public final Warner noWarnings;
104104
public final boolean dumpStacktraceOnError;
105+
private final Preview preview;
105106
private final boolean allowEnhancedVariableDecls;
106107

107108
// <editor-fold defaultstate="collapsed" desc="Instantiating">
@@ -118,7 +119,7 @@ protected Types(Context context) {
118119
syms = Symtab.instance(context);
119120
names = Names.instance(context);
120121
Source source = Source.instance(context);
121-
Preview preview = Preview.instance(context);
122+
preview = Preview.instance(context);
122123
chk = Check.instance(context);
123124
enter = Enter.instance(context);
124125
capturedName = names.fromString("<captured wildcard>");
@@ -2411,11 +2412,16 @@ public boolean isAssignable(Type t, Type s, Warner warn) {
24112412
break;
24122413
}
24132414
}
2414-
if (allowEnhancedVariableDecls && isNR1S(t, s)) {
2415+
2416+
if (isConvertible(t, s, warn)) {
24152417
return true;
2416-
}
2417-
else {
2418-
return isConvertible(t, s, warn);
2418+
} else if (allowEnhancedVariableDecls && isNR1S(t, s)){
2419+
if (warn.pos() != null) {
2420+
preview.warnPreview(warn.pos(), Feature.ENHANCED_VARIABLE_DECLS);
2421+
}
2422+
return true;
2423+
} else {
2424+
return false;
24192425
}
24202426
}
24212427
// where

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,6 @@ public void visitVarDef(JCVariableDecl tree) {
13221322
if (tree.isImplicitlyTyped()) {
13231323
setupImplicitlyTypedVariable(tree, v.type);
13241324
}
1325-
1326-
if (types.isNR1S(tree.init.type, v.type)) {
1327-
preview.checkSourceLevel(tree.init.pos(), Feature.ENHANCED_VARIABLE_DECLS);
1328-
}
13291325
}
13301326
result = tree.type = v.type;
13311327
if (env.enclClass.sym.isRecord() && tree.sym.owner.kind == TYP && !v.isStatic()) {

test/langtools/tools/javac/patterns/AssignmentNR1S.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @test /nodynamiccopyright/
33
* @summary
44
* @compile/fail/ref=AssignmentNR1SNoPreview.out -XDrawDiagnostics AssignmentNR1S.java
5-
* @compile --enable-preview --source ${jdk.version} AssignmentNR1S.java
5+
* @compile/ref=AssignmentNR1S.preview.out -XDrawDiagnostics -Xlint:preview --enable-preview --source ${jdk.version} AssignmentNR1S.java
66
* @run main/othervm --enable-preview AssignmentNR1S
77
*/
88
import java.util.Objects;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
AssignmentNR1S.java:27:18: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
2+
AssignmentNR1S.java:32:17: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
3+
AssignmentNR1S.java:36:16: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
4+
AssignmentNR1S.java:43:21: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
5+
AssignmentNR1S.java:50:17: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
6+
AssignmentNR1S.java:58:14: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
7+
AssignmentNR1S.java:64:27: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
8+
AssignmentNR1S.java:71:16: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.enhanced.variable.decls)
9+
8 warnings

test/langtools/tools/javac/patterns/AssignmentNR1SRequirePreview.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/langtools/tools/javac/patterns/AssignmentNR1SRequirePreview.out

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/langtools/tools/javac/patterns/AssignmentNR1SRequirePreview.preview.out

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)