mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8277864: Compilation error thrown while doing a boxing conversion on selector expression
Reviewed-by: jlaskey, vromero
This commit is contained in:
parent
f39fe5b3d6
commit
194cdf4e28
@ -347,8 +347,9 @@ public class TransPatterns extends TreeTranslator {
|
||||
}
|
||||
}
|
||||
selector = translate(selector);
|
||||
statements.append(make.at(tree.pos).VarDef(temp, !hasNullCase ? attr.makeNullCheck(selector)
|
||||
: selector));
|
||||
boolean needsNullCheck = !hasNullCase && !seltype.isPrimitive();
|
||||
statements.append(make.at(tree.pos).VarDef(temp, needsNullCheck ? attr.makeNullCheck(selector)
|
||||
: selector));
|
||||
VarSymbol index = new VarSymbol(Flags.SYNTHETIC,
|
||||
names.fromString(tree.pos + target.syntheticNameChar() + "index"),
|
||||
syms.intType,
|
||||
|
||||
@ -28,7 +28,7 @@ import java.util.function.Function;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8262891 8268333 8268896 8269802 8269808 8270151 8269113
|
||||
* @bug 8262891 8268333 8268896 8269802 8269808 8270151 8269113 8277864
|
||||
* @summary Check behavior of pattern switches.
|
||||
* @compile --enable-preview -source ${jdk.version} Switches.java
|
||||
* @run main/othervm --enable-preview Switches
|
||||
@ -85,6 +85,9 @@ public class Switches {
|
||||
assertEquals(2, switchOverNull1());
|
||||
assertEquals(2, switchOverNull2());
|
||||
assertEquals(2, switchOverNull3());
|
||||
assertEquals(5, switchOverPrimitiveInt(0));
|
||||
assertEquals(7, switchOverPrimitiveInt(1));
|
||||
assertEquals(9, switchOverPrimitiveInt(2));
|
||||
}
|
||||
|
||||
void run(Function<Object, Integer> mapper) {
|
||||
@ -591,6 +594,14 @@ public class Switches {
|
||||
};
|
||||
}
|
||||
|
||||
private int switchOverPrimitiveInt(Integer i) {
|
||||
return switch (i) {
|
||||
case 0 -> 5 + 0;
|
||||
case Integer j && j == 1 -> 6 + j;
|
||||
case Integer j -> 7 + j;
|
||||
};
|
||||
}
|
||||
|
||||
//verify that for cases like:
|
||||
//case ConstantClassClash ->
|
||||
//ConstantClassClash is interpreted as a field, not as a class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user