8330387: Crash with a different types patterns (primitive vs generic) in instanceof
Reviewed-by: vromero
This commit is contained in:
parent
d517d2df45
commit
3e3f7cf4bd
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/patterns
@ -2974,10 +2974,10 @@ public class Lower extends TreeTranslator {
|
||||
// preserving the side effects of the value
|
||||
VarSymbol dollar_s = new VarSymbol(FINAL | SYNTHETIC,
|
||||
names.fromString("tmp" + tree.pos + this.target.syntheticNameChar()),
|
||||
tree.expr.type,
|
||||
types.erasure(tree.expr.type),
|
||||
currentMethodSym);
|
||||
JCStatement var = make.at(tree.pos())
|
||||
.VarDef(dollar_s, instanceOfExpr).setType(dollar_s.type);
|
||||
.VarDef(dollar_s, instanceOfExpr);
|
||||
|
||||
if (types.isUnconditionallyExact(tree.expr.type, tree.pattern.type)) {
|
||||
exactnessCheck = make.Literal(BOOLEAN, 1).setType(syms.booleanType.constType(1));
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8304487
|
||||
* @bug 8304487 8327683 8330387
|
||||
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
||||
* @enablePreview
|
||||
* @compile PrimitiveInstanceOfPatternOpWithRecordPatterns.java
|
||||
@ -42,6 +42,7 @@ public class PrimitiveInstanceOfPatternOpWithRecordPatterns {
|
||||
assertEquals(true, unboxingWithObject());
|
||||
assertEquals(true, wideningReferenceConversionUnboxing());
|
||||
assertEquals(true, wideningReferenceConversionUnboxing2());
|
||||
assertEquals(true, wideningReferenceConversionUnboxing3());
|
||||
assertEquals(true, wideningReferenceConversionUnboxingAndWideningPrimitive());
|
||||
assertEquals(true, unboxingAndWideningPrimitiveExact());
|
||||
assertEquals(false, unboxingAndWideningPrimitiveNotExact());
|
||||
@ -114,6 +115,11 @@ public class PrimitiveInstanceOfPatternOpWithRecordPatterns {
|
||||
return i instanceof R_generic2(byte _);
|
||||
}
|
||||
|
||||
public static boolean wideningReferenceConversionUnboxing3() {
|
||||
R_generic<Integer> i = new R_generic<Integer>(0x1000000);
|
||||
return i instanceof R_generic(float _);
|
||||
}
|
||||
|
||||
public static boolean wideningReferenceConversionUnboxingAndWideningPrimitive() {
|
||||
R_generic<Integer> i = new R_generic<Integer>(42);
|
||||
return i instanceof R_generic(double _);
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8304487 8325257
|
||||
* @bug 8304487 8325257 8327683 8330387
|
||||
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
||||
* @enablePreview
|
||||
* @compile PrimitiveInstanceOfPatternOpWithTopLevelPatterns.java
|
||||
@ -44,6 +44,7 @@ public class PrimitiveInstanceOfPatternOpWithTopLevelPatterns {
|
||||
assertEquals(true, unboxingWithObject());
|
||||
assertEquals(true, wideningReferenceConversionUnboxing(42));
|
||||
assertEquals(true, wideningReferenceConversionUnboxing2(Byte.valueOf((byte) 42)));
|
||||
assertEquals(true, wideningReferenceConversionUnboxing3(0x1000000));
|
||||
assertEquals(true, wideningReferenceConversionUnboxingAndWideningPrimitive(42));
|
||||
assertEquals(true, unboxingAndWideningPrimitiveExact());
|
||||
assertEquals(false, unboxingAndWideningPrimitiveNotExact());
|
||||
@ -121,6 +122,10 @@ public class PrimitiveInstanceOfPatternOpWithTopLevelPatterns {
|
||||
return i instanceof byte bb;
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxing3(T i) {
|
||||
return i instanceof float ff;
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxingAndWideningPrimitive(T i) {
|
||||
return i instanceof double ii;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8304487 8325257
|
||||
* @bug 8304487 8325257 8327683 8330387
|
||||
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
||||
* @enablePreview
|
||||
* @compile PrimitiveInstanceOfTypeComparisonOp.java
|
||||
@ -44,6 +44,7 @@ public class PrimitiveInstanceOfTypeComparisonOp {
|
||||
assertEquals(true, unboxingWithObject());
|
||||
assertEquals(true, wideningReferenceConversionUnboxing(42));
|
||||
assertEquals(true, wideningReferenceConversionUnboxing2(Byte.valueOf((byte) 42)));
|
||||
assertEquals(true, wideningReferenceConversionUnboxing3(0x1000000));
|
||||
assertEquals(true, wideningReferenceConversionUnboxingAndWideningPrimitive(42));
|
||||
assertEquals(true, unboxingAndWideningPrimitiveExact());
|
||||
assertEquals(false, unboxingAndWideningPrimitiveNotExact());
|
||||
@ -121,6 +122,10 @@ public class PrimitiveInstanceOfTypeComparisonOp {
|
||||
return i instanceof byte;
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxing3(T i) {
|
||||
return i instanceof float;
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxingAndWideningPrimitive(T i) {
|
||||
return i instanceof double;
|
||||
}
|
||||
|
@ -261,4 +261,8 @@ public class PrimitivePatternsSwitchErrors {
|
||||
case char c -> c; // Error - not exhaustive and not allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxingAndNarrowingPrimitive(T i) {
|
||||
return i instanceof byte b; // not allowed as a conversion
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ PrimitivePatternsSwitchErrors.java:216:18: compiler.err.prob.found.req: (compile
|
||||
PrimitivePatternsSwitchErrors.java:248:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Long, char)
|
||||
PrimitivePatternsSwitchErrors.java:255:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Long, int)
|
||||
PrimitivePatternsSwitchErrors.java:261:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Short, char)
|
||||
PrimitivePatternsSwitchErrors.java:266:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: T, byte)
|
||||
PrimitivePatternsSwitchErrors.java:30:16: compiler.err.not.exhaustive
|
||||
PrimitivePatternsSwitchErrors.java:37:16: compiler.err.not.exhaustive
|
||||
PrimitivePatternsSwitchErrors.java:44:16: compiler.err.not.exhaustive
|
||||
@ -43,4 +44,4 @@ PrimitivePatternsSwitchErrors.java:254:16: compiler.err.not.exhaustive
|
||||
PrimitivePatternsSwitchErrors.java:260:16: compiler.err.not.exhaustive
|
||||
- compiler.note.preview.filename: PrimitivePatternsSwitchErrors.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
43 errors
|
||||
44 errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user