8332463: Byte conditional pattern case element dominates short constant case element
Reviewed-by: vromero
This commit is contained in:
parent
d59c12fe10
commit
c4557a7b0d
@ -4818,7 +4818,6 @@ public class Check {
|
|||||||
JCCaseLabel testCaseLabel = caseAndLabel.snd;
|
JCCaseLabel testCaseLabel = caseAndLabel.snd;
|
||||||
Type testType = labelType(testCaseLabel);
|
Type testType = labelType(testCaseLabel);
|
||||||
boolean dominated = false;
|
boolean dominated = false;
|
||||||
if (unconditionalCaseLabel == testCaseLabel) unconditionalFound = true;
|
|
||||||
if (types.isUnconditionallyExact(currentType, testType) &&
|
if (types.isUnconditionallyExact(currentType, testType) &&
|
||||||
!currentType.hasTag(ERROR) && !testType.hasTag(ERROR)) {
|
!currentType.hasTag(ERROR) && !testType.hasTag(ERROR)) {
|
||||||
//the current label is potentially dominated by the existing (test) label, check:
|
//the current label is potentially dominated by the existing (test) label, check:
|
||||||
@ -4833,11 +4832,6 @@ public class Check {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Domination can occur even when we have not an unconditional pair between case labels.
|
|
||||||
if (unconditionalFound && unconditionalCaseLabel != label) {
|
|
||||||
dominated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dominated) {
|
if (dominated) {
|
||||||
log.error(label.pos(), Errors.PatternDominated);
|
log.error(label.pos(), Errors.PatternDominated);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* @test /nodynamiccopyright/
|
* @test /nodynamiccopyright/
|
||||||
* @bug 8304487 8325653
|
* @bug 8304487 8325653 8332463
|
||||||
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
||||||
* @enablePreview
|
* @enablePreview
|
||||||
* @compile/fail/ref=PrimitivePatternsSwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW PrimitivePatternsSwitchErrors.java
|
* @compile/fail/ref=PrimitivePatternsSwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW PrimitivePatternsSwitchErrors.java
|
||||||
@ -59,7 +59,7 @@ public class PrimitivePatternsSwitchErrors {
|
|||||||
int i = 42;
|
int i = 42;
|
||||||
return switch (i) {
|
return switch (i) {
|
||||||
case Integer ib -> ib;
|
case Integer ib -> ib;
|
||||||
case byte ip -> ip; // Error - dominated!
|
case byte ip -> ip; // OK - not dominated!
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
PrimitivePatternsSwitchErrors.java:15:18: compiler.err.pattern.dominated
|
PrimitivePatternsSwitchErrors.java:15:18: compiler.err.pattern.dominated
|
||||||
PrimitivePatternsSwitchErrors.java:24:18: compiler.err.pattern.dominated
|
PrimitivePatternsSwitchErrors.java:24:18: compiler.err.pattern.dominated
|
||||||
PrimitivePatternsSwitchErrors.java:31:24: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.Long)
|
PrimitivePatternsSwitchErrors.java:31:24: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.Long)
|
||||||
PrimitivePatternsSwitchErrors.java:62:18: compiler.err.pattern.dominated
|
|
||||||
PrimitivePatternsSwitchErrors.java:70:18: compiler.err.pattern.dominated
|
PrimitivePatternsSwitchErrors.java:70:18: compiler.err.pattern.dominated
|
||||||
PrimitivePatternsSwitchErrors.java:78:18: compiler.err.pattern.dominated
|
PrimitivePatternsSwitchErrors.java:78:18: compiler.err.pattern.dominated
|
||||||
PrimitivePatternsSwitchErrors.java:84:18: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, byte)
|
PrimitivePatternsSwitchErrors.java:84:18: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, byte)
|
||||||
@ -44,4 +43,4 @@ PrimitivePatternsSwitchErrors.java:254:16: compiler.err.not.exhaustive
|
|||||||
PrimitivePatternsSwitchErrors.java:260:16: compiler.err.not.exhaustive
|
PrimitivePatternsSwitchErrors.java:260:16: compiler.err.not.exhaustive
|
||||||
- compiler.note.preview.filename: PrimitivePatternsSwitchErrors.java, DEFAULT
|
- compiler.note.preview.filename: PrimitivePatternsSwitchErrors.java, DEFAULT
|
||||||
- compiler.note.preview.recompile
|
- compiler.note.preview.recompile
|
||||||
44 errors
|
43 errors
|
54
test/langtools/tools/javac/patterns/T8332463a.java
Normal file
54
test/langtools/tools/javac/patterns/T8332463a.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8332463
|
||||||
|
* @summary Byte conditional pattern case element dominates short constant case element
|
||||||
|
* @compile --enable-preview --source ${jdk.version} T8332463a.java
|
||||||
|
*/
|
||||||
|
public class T8332463a {
|
||||||
|
public int test2() {
|
||||||
|
Byte i = (byte) 42;
|
||||||
|
return switch (i) {
|
||||||
|
case Byte ib -> 1;
|
||||||
|
case short s -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int test4() {
|
||||||
|
int i = 42;
|
||||||
|
return switch (i) {
|
||||||
|
case Integer ib -> 1;
|
||||||
|
case byte ip -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int test3() {
|
||||||
|
int i = 42;
|
||||||
|
return switch (i) {
|
||||||
|
case Integer ib -> 1;
|
||||||
|
case (byte) 0 -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
40
test/langtools/tools/javac/patterns/T8332463b.java
Normal file
40
test/langtools/tools/javac/patterns/T8332463b.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8332463
|
||||||
|
* @summary Byte conditional pattern case element dominates short constant case element
|
||||||
|
* @enablePreview
|
||||||
|
* @compile T8332463b.java
|
||||||
|
* @compile --enable-preview --source ${jdk.version} T8332463b.java
|
||||||
|
*/
|
||||||
|
public class T8332463b {
|
||||||
|
public int test1() {
|
||||||
|
Byte i = (byte) 42;
|
||||||
|
return switch (i) {
|
||||||
|
case Byte ib -> 1;
|
||||||
|
case (short) 0 -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user