[java-highlighting] IDEA-352588 Support JEP 455: highlighting for switch with primitives

GitOrigin-RevId: 06636352b202037ec3400b2f9763e101d8ed6042
This commit is contained in:
Mikhail Pyltsin
2024-04-29 12:51:04 +02:00
committed by intellij-monorepo-bot
parent 63bef6eeac
commit 45160db0df
24 changed files with 5280 additions and 98 deletions

View File

@@ -209,7 +209,7 @@ public final class HighlightUtil {
boolean operandIsPrimitive = TypeConversionUtil.isPrimitiveAndNotNull(operandType);
boolean checkIsPrimitive = TypeConversionUtil.isPrimitiveAndNotNull(checkType);
boolean convertible = TypeConversionUtil.areTypesConvertible(operandType, checkType);
boolean primitiveInPatternsEnabled = JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(PsiUtil.getLanguageLevel(expression));
boolean primitiveInPatternsEnabled = PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, expression);
if (((operandIsPrimitive || checkIsPrimitive) && !primitiveInPatternsEnabled) || !convertible) {
String message = JavaErrorBundle.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil
.formatType(checkType));

View File

@@ -257,7 +257,7 @@ final class PatternHighlightingModel {
PsiType selectorType = cacheContext.mySelectorType;
HashMap<ReduceResultCacheContext, ReduceResult> cache = new HashMap<>();
LoopReduceResult result = reduceInLoop(selectorType, context, new HashSet<>(patterns),
(descriptionPatterns, type) -> coverSelectorType(descriptionPatterns, selectorType), cache);
(descriptionPatterns, type) -> coverSelectorType(context, descriptionPatterns, selectorType), cache);
if (result.stopped()) {
return RecordExhaustivenessResult.createExhaustiveResult();
}
@@ -391,7 +391,7 @@ final class PatternHighlightingModel {
Set<PsiType> existedTypes = StreamEx.of(typeTestDescriptions).map(t -> t.type()).toSet();
Set<PsiClass> visitedCovered =
findMissedClasses(mySelectorType, new ArrayList<>(typeTestDescriptions), List.of(), context).coveredClasses();
boolean changed = addNewClasses(mySelectorType, visitedCovered, existedTypes, toAdd);
boolean changed = addNewClasses(context, mySelectorType, visitedCovered, existedTypes, toAdd);
if (!changed) {
return new ReduceResult(currentPatterns, false);
}
@@ -561,7 +561,7 @@ final class PatternHighlightingModel {
for (int i = 0; i < recordComponentTypes.size(); i++) {
PsiType recordComponentType = recordComponentTypes.get(i);
PsiType descriptionComponentType = descriptionTypes.get(i);
if (!SwitchBlockHighlightingModel.oneOfUnconditional(descriptionComponentType, recordComponentType)) {
if (!SwitchBlockHighlightingModel.cover(context, descriptionComponentType, recordComponentType)) {
allCovered = false;
break;
}
@@ -654,7 +654,8 @@ final class PatternHighlightingModel {
return result;
}
private static boolean addNewClasses(@NotNull PsiType selectorType,
private static boolean addNewClasses(@NotNull PsiElement context,
@NotNull PsiType selectorType,
@NotNull Set<PsiClass> visitedCovered,
@NotNull Set<PsiType> existedTypes,
@NotNull Collection<PatternTypeTestDescription> toAdd) {
@@ -662,12 +663,12 @@ final class PatternHighlightingModel {
for (PsiClass covered : visitedCovered) {
PsiClassType classType = TypeUtils.getType(covered);
if (!existedTypes.contains(classType)) {
if (SwitchBlockHighlightingModel.oneOfUnconditional(selectorType, classType)) {
if (SwitchBlockHighlightingModel.cover(context, selectorType, classType)) {
toAdd.add(new PatternTypeTestDescription(classType));
changed = true;
}
//find something upper. let's change to selectorType
if (SwitchBlockHighlightingModel.oneOfUnconditional(classType, selectorType)) {
if (SwitchBlockHighlightingModel.cover(context, classType, selectorType)) {
toAdd.add(new PatternTypeTestDescription(selectorType));
changed = true;
break;
@@ -776,7 +777,7 @@ final class PatternHighlightingModel {
Set<PsiClass> sealedResult =
findMissedClasses(componentType, nestedTypeDescriptions, new ArrayList<>(), context).missedClasses();
if (!sealedResult.isEmpty()) {
addNewClasses(componentType, sealedResult, existedTypes, missedComponentTypeDescription);
addNewClasses(context, componentType, sealedResult, existedTypes, missedComponentTypeDescription);
}
else {
combinedPatterns.removeAll(setWithOneDifferentElement);
@@ -788,7 +789,7 @@ final class PatternHighlightingModel {
Collection<PatternDeconstructionDescription> newPatterns =
createPatternsFrom(i, missedComponentTypeDescription, setWithOneDifferentElement.iterator().next());
for (PatternDeconstructionDescription pattern : newPatterns) {
if (ContainerUtil.exists(filtered, existedPattern -> oneOfUnconditional(existedPattern, pattern))) {
if (ContainerUtil.exists(filtered, existedPattern -> oneOfUnconditional(context, existedPattern, pattern))) {
continue;
}
missingRecordPatternsForThisIteration.add(pattern);
@@ -806,7 +807,7 @@ final class PatternHighlightingModel {
}
}
LoopReduceResult reduceResult = reduceInLoop(selectorType, context, combinedPatterns, (set, type) -> false, cache);
return coverSelectorType(reduceResult.patterns(), selectorType) ? new ArrayList<>(missingRecordPatterns) : null;
return coverSelectorType(context, reduceResult.patterns(), selectorType) ? new ArrayList<>(missingRecordPatterns) : null;
}
@NotNull
@@ -846,7 +847,8 @@ final class PatternHighlightingModel {
return filtered;
}
private static boolean oneOfUnconditional(@NotNull PatternDeconstructionDescription whoType,
private static boolean oneOfUnconditional(@NotNull PsiElement context,
@NotNull PatternDeconstructionDescription whoType,
@NotNull PatternDeconstructionDescription overWhom) {
if (!whoType.type().equals(overWhom.type())) {
return false;
@@ -855,17 +857,19 @@ final class PatternHighlightingModel {
return false;
}
for (int i = 0; i < whoType.list().size(); i++) {
if (!SwitchBlockHighlightingModel.oneOfUnconditional(whoType.list().get(i).type(), overWhom.list().get(i).type())) {
if (!SwitchBlockHighlightingModel.cover(context, whoType.list().get(i).type(), overWhom.list().get(i).type())) {
return false;
}
}
return true;
}
private static boolean coverSelectorType(@NotNull Set<? extends PatternDescription> patterns,
private static boolean coverSelectorType(@NotNull PsiElement context,
@NotNull Set<? extends PatternDescription> patterns,
@NotNull PsiType selectorType) {
for (PatternDescription pattern : patterns) {
if (pattern instanceof PatternTypeTestDescription && SwitchBlockHighlightingModel.oneOfUnconditional(pattern.type(), selectorType)) {
if (pattern instanceof PatternTypeTestDescription &&
SwitchBlockHighlightingModel.cover(context, pattern.type(), selectorType)) {
return true;
}
}

View File

@@ -41,7 +41,7 @@ import static com.intellij.psi.PsiModifier.ABSTRACT;
import static com.intellij.psi.PsiModifier.SEALED;
public class SwitchBlockHighlightingModel {
@NotNull private final LanguageLevel myLevel;
@NotNull final LanguageLevel myLevel;
@NotNull final PsiSwitchBlock myBlock;
@NotNull final PsiExpression mySelector;
@NotNull final PsiType mySelectorType;
@@ -182,7 +182,9 @@ public class SwitchBlockHighlightingModel {
IntentionAction action = getFixFactory().createConvertSwitchToIfIntention(switchStatement);
builder.registerFix(action, null, null, null, null);
}
if (PsiTypes.longType().equals(mySelectorType) || PsiTypes.floatType().equals(mySelectorType) || PsiTypes.doubleType().equals(mySelectorType)) {
if (PsiTypes.longType().equals(mySelectorType) ||
PsiTypes.floatType().equals(mySelectorType) ||
PsiTypes.doubleType().equals(mySelectorType)) {
IntentionAction addTypeCastFix = getFixFactory().createAddTypeCastFix(PsiTypes.intType(), mySelector);
builder.registerFix(addTypeCastFix, null, null, null, null);
IntentionAction wrapWithAdapterFix = getFixFactory().createWrapWithAdapterFix(PsiTypes.intType(), mySelector);
@@ -261,7 +263,7 @@ public class SwitchBlockHighlightingModel {
if (!reported && myBlock instanceof PsiSwitchExpression && !hasDefaultCase) {
PsiClass selectorClass = PsiUtil.resolveClassInClassTypeOnly(mySelectorType);
if (selectorClass != null && selectorClass.isEnum()) {
List<PsiEnumConstant> enumConstants = ContainerUtil.mapNotNull(values.values(), element->getEnumConstant(element));
List<PsiEnumConstant> enumConstants = ContainerUtil.mapNotNull(values.values(), element -> getEnumConstant(element));
checkEnumCompleteness(selectorClass, enumConstants, !values.values().isEmpty(), errorSink);
}
else {
@@ -282,7 +284,7 @@ public class SwitchBlockHighlightingModel {
@Nullable
private static String evaluateEnumConstantName(@NotNull PsiReferenceExpression expr) {
PsiEnumConstant enumConstant = getEnumConstant(expr);
if (enumConstant !=null) return enumConstant.getName();
if (enumConstant != null) return enumConstant.getName();
return null;
}
@@ -373,8 +375,7 @@ public class SwitchBlockHighlightingModel {
}
private boolean isEnhancedSwitch(@NotNull List<? extends PsiCaseLabelElement> labelElements) {
boolean selectorIsTypeOrClass = getSwitchSelectorKind() == SelectorKind.CLASS_OR_ARRAY;
return JavaPsiSwitchUtil.isEnhancedSwitch(labelElements, selectorIsTypeOrClass);
return JavaPsiSwitchUtil.isEnhancedSwitch(labelElements, mySelectorType);
}
private static boolean isNullType(@NotNull PsiElement element) {
@@ -398,7 +399,7 @@ public class SwitchBlockHighlightingModel {
@NotNull
static LinkedHashSet<PsiEnumConstant> findMissingEnumConstant(@NotNull PsiClass selectorClass,
@NotNull List<PsiEnumConstant> enumElements) {
@NotNull List<PsiEnumConstant> enumElements) {
LinkedHashSet<PsiEnumConstant> missingConstants =
StreamEx.of(selectorClass.getFields()).select(PsiEnumConstant.class).toCollection(LinkedHashSet::new);
if (!enumElements.isEmpty()) {
@@ -458,7 +459,7 @@ public class SwitchBlockHighlightingModel {
if (list != null) {
if (!ContainerUtil.exists(list.getElements(), e -> e instanceof PsiPattern)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(guardingExpr)
.descriptionAndTooltip(JavaErrorBundle.message("error.guard.allowed.after.patterns.only"));
.descriptionAndTooltip(JavaErrorBundle.message("error.guard.allowed.after.patterns.only"));
}
}
HighlightInfo.Builder info2 = checkGuardingExpressionHasBooleanType(guardingExpr);
@@ -483,7 +484,10 @@ public class SwitchBlockHighlightingModel {
return null;
}
private enum SelectorKind {INT, ENUM, STRING, CLASS_OR_ARRAY}
private enum SelectorKind {
INT, ENUM, STRING, CLASS_OR_ARRAY,
BOOLEAN, LONG, FLOAT, DOUBLE // primitives from Java 22 Preview
}
private static Set<PsiClass> findSealedUpperClasses(Set<PsiClass> classes) {
HashSet<PsiClass> sealedUpperClasses = new HashSet<>();
@@ -548,27 +552,34 @@ public class SwitchBlockHighlightingModel {
});
}
static boolean oneOfUnconditional(@NotNull PsiType whoType, @NotNull PsiType overWhom) {
static boolean cover(@NotNull PsiElement context, @NotNull PsiType whoType, @NotNull PsiType overWhom) {
List<PsiType> whoTypes = getAllTypes(whoType);
List<PsiType> overWhomTypes = getAllTypes(overWhom);
for (PsiType currentWhoType : whoTypes) {
if (!ContainerUtil.exists(overWhomTypes, currentOverWhomType -> JavaPsiPatternUtil.dominates(currentWhoType, currentOverWhomType))) {
if (!ContainerUtil.exists(overWhomTypes, currentOverWhomType -> {
boolean unconditionallyExactForType = JavaPsiPatternUtil.isUnconditionallyExactForType(context, currentOverWhomType, currentWhoType);
if(unconditionallyExactForType) return true;
PsiPrimitiveType unboxedOverWhomType = PsiPrimitiveType.getUnboxedType(currentOverWhomType);
if (unboxedOverWhomType == null) return false;
return JavaPsiPatternUtil.isUnconditionallyExactForType(context, unboxedOverWhomType, currentWhoType);
})) {
return false;
}
}
return true;
}
record SealedResult(@NotNull Set<PsiClass> missedClasses, @NotNull Set<PsiClass> coveredClasses) { }
record SealedResult(@NotNull Set<PsiClass> missedClasses, @NotNull Set<PsiClass> coveredClasses) {
}
/**
* Finds the missed and covered classes for a sealed selector type.
* If a selector type is not sealed classes, it will be checked if it is covered by one of the elements or enumConstants
*
* @param selectorType the selector type
* @param elements the pattern descriptions, unconditional
* @param enumConstants the enum constants, which can be used to cover enum classes
* @param context the context element (parent of pattern descriptions)
* @param selectorType the selector type
* @param elements the pattern descriptions, unconditional
* @param enumConstants the enum constants, which can be used to cover enum classes
* @param context the context element (parent of pattern descriptions)
* @return the container of missed and covered classes (may contain classes outside the selector type hierarchy)
*/
static @NotNull SealedResult findMissedClasses(@NotNull PsiType selectorType,
@@ -593,7 +604,8 @@ public class SwitchBlockHighlightingModel {
List<PatternTypeTestDescription> typeTestPatterns = ContainerUtil.filterIsInstance(elements, PatternTypeTestDescription.class);
Set<PsiClass> selectorClasses = ContainerUtil.map2SetNotNull(getAllTypes(selectorType),
type -> PsiUtil.resolveClassInClassTypeOnly(TypeConversionUtil.erasure(type)));
type -> PsiUtil.resolveClassInClassTypeOnly(
TypeConversionUtil.erasure(type)));
if (selectorClasses.isEmpty()) return new SealedResult(Collections.emptySet(), Collections.emptySet());
Queue<ClassWithDependencies> nonVisited = new ArrayDeque<>();
@@ -621,11 +633,13 @@ public class SwitchBlockHighlightingModel {
if (patternTypes.isEmpty() && TypeConversionUtil.areTypesConvertible(selectorType, permittedType) ||
//if permittedClass is covered by existed patternType, we don't have to go further
!patternTypes.isEmpty() && !ContainerUtil.exists(patternTypes,
patternType -> oneOfUnconditional(patternType, TypeUtils.getType(permittedClass)))) {
patternType -> cover(context, patternType,
TypeUtils.getType(permittedClass)))) {
List<PsiClass> dependentClasses = new ArrayList<>(peeked.dependencies);
dependentClasses.add(permittedClass);
nonVisited.add(new ClassWithDependencies(permittedClass, dependentClasses));
} else {
}
else {
if (!patternTypes.isEmpty()) {
coveredClasses.addAll(peeked.dependencies);
}
@@ -637,9 +651,9 @@ public class SwitchBlockHighlightingModel {
//there is a chance, that tree goes away from a target type
if (TypeConversionUtil.areTypesConvertible(targetType, selectorType) ||
//we should consider items from the intersections in the usual way
oneOfUnconditional(targetType, selectorType)) {
cover(context, targetType, selectorType)) {
if (//check a case, when we have something, which not in sealed hierarchy, but covers some leaves
!ContainerUtil.exists(typeTestPatterns, pattern -> oneOfUnconditional(pattern.type(), targetType))) {
!ContainerUtil.exists(typeTestPatterns, pattern -> cover(context, pattern.type(), targetType))) {
missingClasses.add(psiClass);
visitedNotCovered.addAll(peeked.dependencies);
}
@@ -669,23 +683,29 @@ public class SwitchBlockHighlightingModel {
return psiClass != null && (psiClass.hasModifierProperty(SEALED) || psiClass.getPermitsList() != null);
}
//todo extract into separate file after merging
public static class PatternsInSwitchBlockHighlightingModel extends SwitchBlockHighlightingModel {
private final Object myUnconditionalPattern = new Object();
@Nullable
private final SelectorKind mySelectorKind;
PatternsInSwitchBlockHighlightingModel(@NotNull LanguageLevel languageLevel,
@NotNull PsiSwitchBlock switchBlock,
@NotNull PsiFile psiFile) {
super(languageLevel, switchBlock, psiFile);
mySelectorKind = getSwitchSelectorKind();
}
@Override
void checkSwitchSelectorType(@NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
SelectorKind kind = getSwitchSelectorKind();
if (kind == SelectorKind.INT) return;
if (kind == null) {
if (mySelectorKind == SelectorKind.INT) return;
if (mySelectorKind == null) {
HighlightInfo.Builder info = createError(mySelector, JavaErrorBundle.message("switch.invalid.selector.types",
JavaHighlightUtil.formatType(mySelectorType)));
registerFixesOnInvalidSelector(info);
if (mySelectorType instanceof PsiPrimitiveType) {
HighlightUtil.registerIncreaseLanguageLevelFixes(mySelector, JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, info);
}
errorSink.accept(info);
}
checkIfAccessibleType(errorSink);
@@ -695,6 +715,21 @@ public class SwitchBlockHighlightingModel {
@Nullable
SelectorKind getSwitchSelectorKind() {
if (TypeConversionUtil.getTypeRank(mySelectorType) <= TypeConversionUtil.INT_RANK) return SelectorKind.INT;
PsiType unboxedType = PsiPrimitiveType.getOptionallyUnboxedType(mySelectorType);
if (unboxedType != null && PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, mySelector)) {
if (unboxedType.equals(PsiTypes.longType())) {
return SelectorKind.LONG;
}
else if (unboxedType.equals(PsiTypes.booleanType())) {
return SelectorKind.BOOLEAN;
}
else if (unboxedType.equals(PsiTypes.floatType())) {
return SelectorKind.FLOAT;
}
else if (unboxedType.equals(PsiTypes.doubleType())) {
return SelectorKind.DOUBLE;
}
}
if (TypeConversionUtil.isPrimitiveAndNotNull(mySelectorType)) return null;
PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(mySelectorType);
if (psiClass != null) {
@@ -762,7 +797,8 @@ public class SwitchBlockHighlightingModel {
}
}
private boolean checkLabelAndSelectorCompatibility(@NotNull PsiCaseLabelElement label, @NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
private boolean checkLabelAndSelectorCompatibility(@NotNull PsiCaseLabelElement label,
@NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
if (label instanceof PsiDefaultCaseLabelElement) return false;
if (!(label instanceof PsiParenthesizedExpression) && isNullType(label)) {
if (mySelectorType instanceof PsiPrimitiveType && !isNullType(mySelector)) {
@@ -779,7 +815,8 @@ public class SwitchBlockHighlightingModel {
PsiTypeElement typeElement = JavaPsiPatternUtil.getPatternTypeElement(elementToReport);
if (typeElement == null) return false;
PsiType patternType = typeElement.getType();
if (!(patternType instanceof PsiClassType) && !(patternType instanceof PsiArrayType)) {
if (!(patternType instanceof PsiClassType) && !(patternType instanceof PsiArrayType) &&
!JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(myLevel)) {
String expectedTypes = JavaErrorBundle.message("switch.class.or.array.type.expected");
String message = JavaErrorBundle.message("unexpected.type", expectedTypes, JavaHighlightUtil.formatType(patternType));
HighlightInfo.Builder info = createError(elementToReport, message);
@@ -794,11 +831,13 @@ public class SwitchBlockHighlightingModel {
return true;
}
if ((!ContainerUtil.and(getAllTypes(mySelectorType), type -> TypeConversionUtil.areTypesConvertible(type, patternType)) ||
// 14.30.3 A type pattern that declares a pattern variable of a reference type U is
// applicable at another reference type T if T is checkcast convertible to U (JEP 440-441)
// There is no rule that says that a reference type applies to a primitive type
(mySelectorType instanceof PsiPrimitiveType && PsiUtil.isAvailable(JavaFeature.PATTERN_GUARDS_AND_RECORD_PATTERNS,
label))) &&
// 14.30.3 A type pattern that declares a pattern variable of a reference type U is
// applicable at another reference type T if T is checkcast convertible to U (JEP 440-441)
// There is no rule that says that a reference type applies to a primitive type
(mySelectorType instanceof PsiPrimitiveType &&
PsiUtil.isAvailable(JavaFeature.PATTERN_GUARDS_AND_RECORD_PATTERNS, label)) &&
//from JEP 455 it is allowed
!PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, label)) &&
//null type is applicable to any class type
!mySelectorType.equals(PsiTypes.nullType())) {
HighlightInfo.Builder error =
@@ -843,13 +882,28 @@ public class SwitchBlockHighlightingModel {
errorSink.accept(error);
return true;
}
SelectorKind kind = mySelectorKind;
if (isExtendedPrimitiveSelector()) {
if ((kind == SelectorKind.LONG && !(constValue instanceof Long)) ||
(kind == SelectorKind.DOUBLE && !(constValue instanceof Double)) ||
(kind == SelectorKind.FLOAT && !(constValue instanceof Float)) ||
(kind == SelectorKind.BOOLEAN && !(constValue instanceof Boolean))) {
PsiType unboxedType = PsiPrimitiveType.getOptionallyUnboxedType(mySelectorType);
if (unboxedType != null) {
HighlightInfo.Builder error =
HighlightUtil.createIncompatibleTypeHighlightInfo(unboxedType, expr.getType(), label.getTextRange(), 0);
errorSink.accept(error);
return true;
}
}
return false;
}
if (ConstantExpressionUtil.computeCastTo(constValue, mySelectorType) == null) {
HighlightInfo.Builder error =
HighlightUtil.createIncompatibleTypeHighlightInfo(mySelectorType, expr.getType(), label.getTextRange(), 0);
errorSink.accept(error);
return true;
}
SelectorKind kind = getSwitchSelectorKind();
if (kind == SelectorKind.INT || kind == SelectorKind.STRING) {
return false;
}
@@ -878,7 +932,12 @@ public class SwitchBlockHighlightingModel {
}
Object operand = evaluateConstant(labelElement);
if (operand != null) {
elements.putValue(ConstantExpressionUtil.computeCastTo(operand, mySelectorType), labelElement);
if (operand instanceof Boolean booleanOperand && mySelectorKind == SelectorKind.BOOLEAN) {
elements.putValue(booleanOperand.booleanValue(), labelElement);
}
else {
elements.putValue(ConstantExpressionUtil.computeCastTo(operand, mySelectorType), labelElement);
}
}
if (labelElement instanceof PsiLiteralExpression literalExpression && literalExpression.getType() == PsiTypes.nullType()) {
elements.putValue(null, labelElement);
@@ -889,6 +948,13 @@ public class SwitchBlockHighlightingModel {
}
}
private boolean isExtendedPrimitiveSelector() {
return mySelectorKind == SelectorKind.BOOLEAN ||
mySelectorKind == SelectorKind.FLOAT ||
mySelectorKind == SelectorKind.DOUBLE ||
mySelectorKind == SelectorKind.LONG;
}
private static void fillElementsToCheckFallThroughLegality(@NotNull List<List<PsiSwitchLabelStatementBase>> elements,
@NotNull PsiSwitchLabelStatementBase labelStatement,
int switchBlockGroupCounter) {
@@ -924,7 +990,10 @@ public class SwitchBlockHighlightingModel {
public static boolean isDominated(@NotNull PsiCaseLabelElement overWhom,
@NotNull PsiElement who,
@NotNull PsiType selectorType) {
if (!JavaPsiPatternUtil.isUnconditionalForType(overWhom, selectorType) &&
boolean isOverWhomUnconditionalForSelector = JavaPsiPatternUtil.isUnconditionalForType(overWhom, selectorType);
boolean isWhoUnconditionalForSelector = who instanceof PsiCaseLabelElement whoCase &&
JavaPsiPatternUtil.isUnconditionalForType(whoCase, selectorType);
if (!isOverWhomUnconditionalForSelector &&
((!(overWhom instanceof PsiExpression expression) || ExpressionUtils.isNullLiteral(expression)) &&
who instanceof PsiKeyword &&
PsiKeyword.DEFAULT.equals(who.getText()) || isInCaseNullDefaultLabel(who))) {
@@ -934,6 +1003,12 @@ public class SwitchBlockHighlightingModel {
// A 'case null, default' label dominates all other switch labels.
return true;
}
if (isWhoUnconditionalForSelector && !isOverWhomUnconditionalForSelector &&
!(isInCaseNullDefaultLabel(overWhom) ||
(overWhom instanceof PsiKeyword && PsiKeyword.DEFAULT.equals(overWhom.getText())) ||
(overWhom instanceof PsiExpression expression && ExpressionUtils.isNullLiteral(expression)))) {
return true;
}
if (who instanceof PsiCaseLabelElement currentElement) {
if (JavaPsiPatternUtil.isGuarded(currentElement)) return false;
if (isConstantLabelElement(overWhom)) {
@@ -999,7 +1074,8 @@ public class SwitchBlockHighlightingModel {
PsiCaseLabelElement[] elements = labelElementList.getElements();
final PsiCaseLabelElement first = elements[0];
if (problem != null) {
HighlightInfo.Builder info = addIllegalFallThroughError(problem.element(), problem.message(), problem.customAction(), alreadyFallThroughElements);
HighlightInfo.Builder info =
addIllegalFallThroughError(problem.element(), problem.message(), problem.customAction(), alreadyFallThroughElements);
errorSink.accept(info);
reported = true;
}
@@ -1034,7 +1110,7 @@ public class SwitchBlockHighlightingModel {
PsiCaseLabelElement firstElement = elements[0];
if (elements.length == 1) {
if (firstElement instanceof PsiDefaultCaseLabelElement) {
ModCommandAction fix = SwitchBlockHighlightingModel.getFixFactory().createReplaceCaseDefaultWithDefaultFix(labelElementList);
ModCommandAction fix = getFixFactory().createReplaceCaseDefaultWithDefaultFix(labelElementList);
return new CaseLabelCombinationProblem(firstElement, "default.label.must.not.contains.case.keyword", fix);
}
return null;
@@ -1043,7 +1119,7 @@ public class SwitchBlockHighlightingModel {
if (firstElement instanceof PsiDefaultCaseLabelElement &&
elements[1] instanceof PsiExpression expr &&
ExpressionUtils.isNullLiteral(expr)) {
ModCommandAction fix = SwitchBlockHighlightingModel.getFixFactory().createReverseCaseDefaultNullFixFix(labelElementList);
ModCommandAction fix = getFixFactory().createReverseCaseDefaultNullFixFix(labelElementList);
return new CaseLabelCombinationProblem(firstElement, "invalid.default.and.null.order", fix);
}
if (firstElement instanceof PsiExpression expr &&
@@ -1090,7 +1166,8 @@ public class SwitchBlockHighlightingModel {
if (patternVarElement != null) {
return new CaseLabelCombinationProblem(patternVarElement, "invalid.case.label.combination.several.patterns.unnamed", null);
}
} else {
}
else {
return new CaseLabelCombinationProblem(elements[1], "invalid.case.label.combination.several.patterns", null);
}
}
@@ -1101,7 +1178,8 @@ public class SwitchBlockHighlightingModel {
private static CaseLabelCombinationProblem getPatternConstantCombinationProblem(PsiCaseLabelElement anchor) {
if (PsiUtil.isAvailable(JavaFeature.UNNAMED_PATTERNS_AND_VARIABLES, anchor)) {
return new CaseLabelCombinationProblem(anchor, "invalid.case.label.combination.constants.and.patterns.unnamed", null);
} else {
}
else {
return new CaseLabelCombinationProblem(anchor, "invalid.case.label.combination.constants.and.patterns", null);
}
}
@@ -1121,8 +1199,8 @@ public class SwitchBlockHighlightingModel {
}
private static boolean checkFallThroughToPatternPrecedingCompleteNormally(@NotNull List<? extends List<? extends PsiSwitchLabelStatementBase>> switchBlockGroup,
@NotNull Set<PsiElement> alreadyFallThroughElements,
@NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
@NotNull Set<PsiElement> alreadyFallThroughElements,
@NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
boolean reported = false;
for (int i = 1; i < switchBlockGroup.size(); i++) {
List<? extends PsiSwitchLabelStatementBase> switchLabels = switchBlockGroup.get(i);
@@ -1134,7 +1212,8 @@ public class SwitchBlockHighlightingModel {
PsiCaseLabelElementList labelElementList = switchLabel.getCaseLabelElementList();
if (labelElementList == null) continue;
List<PsiCaseLabelElement> patternElements = ContainerUtil.filter(labelElementList.getElements(),
labelElement -> JavaPsiPatternUtil.containsNamedPatternVariable(labelElement));
labelElement -> JavaPsiPatternUtil.containsNamedPatternVariable(
labelElement));
if (patternElements.isEmpty()) continue;
PsiStatement prevStatement = PsiTreeUtil.getPrevSiblingOfType(firstSwitchLabelInGroup, PsiStatement.class);
if (prevStatement == null) continue;
@@ -1161,7 +1240,8 @@ public class SwitchBlockHighlightingModel {
* @see JavaPsiPatternUtil#isUnconditionalForType(PsiCaseLabelElement, PsiType)
* @see JavaPsiPatternUtil#dominates(PsiCaseLabelElement, PsiCaseLabelElement)
*/
private boolean checkDominance(@NotNull List<? extends PsiElement> switchLabels, @NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
private boolean checkDominance(@NotNull List<? extends PsiElement> switchLabels,
@NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
Map<PsiCaseLabelElement, PsiElement> dominatedLabels = findDominatedLabels(switchLabels);
AtomicBoolean reported = new AtomicBoolean();
dominatedLabels.forEach((overWhom, who) -> {
@@ -1221,11 +1301,32 @@ public class SwitchBlockHighlightingModel {
errorSink.accept(patternInfo);
return;
}
//default (or unconditional), TRUE and FALSE cannot be together
if ((defaultElement != null || elementCoversType != null) && mySelectorKind == SelectorKind.BOOLEAN && elements.size() >= 2) {
if (hasTrueAndFalse(elements)) {
if (defaultElement != null) {
HighlightInfo.Builder defaultInfo =
createError(defaultElement.getFirstChild(), JavaErrorBundle.message("switch.unconditional.boolean.and.default.exist"));
registerDeleteFixForDefaultElement(defaultInfo, defaultElement, defaultElement.getFirstChild());
errorSink.accept(defaultInfo);
}
if (elementCoversType != null) {
HighlightInfo.Builder patternInfo = createError(elementCoversType,
JavaErrorBundle.message(
"switch.unconditional.boolean.and.unconditional.exist"));
IntentionAction action = getFixFactory().createDeleteSwitchLabelFix(elementCoversType);
patternInfo.registerFix(action, null, null, null, null);
errorSink.accept(patternInfo);
}
}
}
if (defaultElement != null || elementCoversType != null) return;
}
if (isExhaustiveForSwitchSelectorPrimitiveWrapper(elements)) return;
if (mySelectorKind == SelectorKind.BOOLEAN && hasTrueAndFalse(elements)) return;
//enums are final; checking intersections are not needed
PsiClass selectorClass = PsiUtil.resolveClassInClassTypeOnly(TypeConversionUtil.erasure(mySelectorType));
if (selectorClass != null && getSwitchSelectorKind() == SelectorKind.ENUM) {
if (selectorClass != null && mySelectorKind == SelectorKind.ENUM) {
List<PsiEnumConstant> enumElements = new SmartList<>();
elements.stream()
.map(SwitchBlockHighlightingModel::getEnumConstant)
@@ -1253,6 +1354,23 @@ public class SwitchBlockHighlightingModel {
}
}
private static boolean hasTrueAndFalse(@NotNull List<? extends PsiCaseLabelElement> elements) {
Set<Object> constants = elements.stream()
.filter(e -> e instanceof PsiExpression expression && PsiTypes.booleanType().equals(expression.getType()))
.map(e -> evaluateConstant(e))
.collect(Collectors.toSet());
return constants.contains(Boolean.TRUE) && constants.contains(Boolean.FALSE);
}
private boolean isExhaustiveForSwitchSelectorPrimitiveWrapper(@NotNull List<? extends PsiCaseLabelElement> elements) {
PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(TypeConversionUtil.erasure(mySelectorType));
if (unboxedType == null) return false;
return ContainerUtil.or(elements, element ->
JavaPsiPatternUtil.findUnconditionalPattern(element) instanceof PsiTypeTestPattern testPattern &&
JavaPsiPatternUtil.getPatternType(testPattern) instanceof PsiPrimitiveType primitiveType &&
JavaPsiPatternUtil.isUnconditionallyExactForType(element, unboxedType, primitiveType));
}
@NotNull
private static List<PsiType> getAbstractSealedTypes(@NotNull List<PsiType> selectorTypes) {
return selectorTypes.stream()
@@ -1332,14 +1450,15 @@ public class SwitchBlockHighlightingModel {
Set<PsiClass> missedClasses;
List<PatternDescription> descriptions = preparePatternDescription(elements);
List<PsiEnumConstant> enumConstants = StreamEx.of(elements).map(element -> getEnumConstant(element)).nonNull().toList();
List<PsiClass> missedSealedClasses = StreamEx.of(findMissedClasses(selectorType, descriptions, enumConstants, myBlock).missedClasses())
.sortedBy(t->t.getQualifiedName())
.toList();
List<PsiClass> missedSealedClasses =
StreamEx.of(findMissedClasses(selectorType, descriptions, enumConstants, myBlock).missedClasses())
.sortedBy(t -> t.getQualifiedName())
.toList();
missedClasses = new LinkedHashSet<>();
//if T is intersection types, it is allowed to choose any of them to cover
for (PsiClass missedClass : missedSealedClasses) {
PsiClassType missedClassType = TypeUtils.getType(missedClass);
if (oneOfUnconditional(missedClassType, selectorType)) {
if (cover(mySelector, missedClassType, selectorType)) {
missedClasses.clear();
missedClasses.add(missedClass);
break;
@@ -1401,7 +1520,7 @@ public class SwitchBlockHighlightingModel {
}
private static boolean isEnumConstant(@NotNull PsiCaseLabelElement element) {
return SwitchBlockHighlightingModel.getEnumConstant(element) != null;
return getEnumConstant(element) != null;
}
@Nullable
@@ -1412,9 +1531,9 @@ public class SwitchBlockHighlightingModel {
/**
* Evaluates the completeness of a switch block.
*
* @param switchBlock the PsiSwitchBlock to evaluate
* @param considerNestedDeconstructionPatterns flag indicating whether to consider nested deconstruction patterns. It is necessary to take into account,
* because nested deconstruction patterns don't cover null values
* @param switchBlock the PsiSwitchBlock to evaluate
* @param considerNestedDeconstructionPatterns flag indicating whether to consider nested deconstruction patterns. It is necessary to take into account,
* because nested deconstruction patterns don't cover null values
* @return {@link CompletenessResult#UNEVALUATED}, if switch is incomplete, and it produces a compilation error
* (this is already covered by highlighting)
* <p>{@link CompletenessResult#INCOMPLETE}, if selector type is not enum or reference type(except boxing primitives and String) or switch is incomplete
@@ -1422,8 +1541,9 @@ public class SwitchBlockHighlightingModel {
* <p>{@link CompletenessResult#COMPLETE_WITHOUT_UNCONDITIONAL}, if switch is complete and doesn't contain an unconditional pattern
*/
@NotNull
public static CompletenessResult evaluateSwitchCompleteness(@NotNull PsiSwitchBlock switchBlock, boolean considerNestedDeconstructionPatterns) {
SwitchBlockHighlightingModel switchModel = SwitchBlockHighlightingModel.createInstance(
public static CompletenessResult evaluateSwitchCompleteness(@NotNull PsiSwitchBlock switchBlock,
boolean considerNestedDeconstructionPatterns) {
SwitchBlockHighlightingModel switchModel = createInstance(
PsiUtil.getLanguageLevel(switchBlock), switchBlock, switchBlock.getContainingFile());
if (switchModel == null) return UNEVALUATED;
PsiCodeBlock switchBody = switchModel.myBlock.getBody();
@@ -1447,7 +1567,9 @@ public class SwitchBlockHighlightingModel {
deconstructionPattern.getDeconstructionList().getDeconstructionComponents(),
component -> component instanceof PsiDeconstructionPattern)));
}
patternsInSwitchModel.checkCompleteness(labelElements, false, builder -> { if (builder != null) reported.set(true); });
patternsInSwitchModel.checkCompleteness(labelElements, false, builder -> {
if (builder != null) reported.set(true);
});
}
else {
if (!needToCheckCompleteness && !isEnumSelector) return INCOMPLETE;
@@ -1456,7 +1578,9 @@ public class SwitchBlockHighlightingModel {
List<PsiSwitchLabelStatementBase> labels =
PsiTreeUtil.getChildrenOfTypeAsList(switchBlock.getBody(), PsiSwitchLabelStatementBase.class);
List<PsiEnumConstant> enumConstants = StreamEx.of(labels).flatCollection(SwitchUtils::findEnumConstants).toList();
switchModel.checkEnumCompleteness(selectorClass, enumConstants, !labels.isEmpty(), builder -> { if (builder != null) reported.set(true); });
switchModel.checkEnumCompleteness(selectorClass, enumConstants, !labels.isEmpty(), builder -> {
if (builder != null) reported.set(true);
});
}
// if a switch block is needed to check completeness and switch is incomplete we let highlighting to inform about it as it's a compilation error
if (needToCheckCompleteness) return reported.get() ? UNEVALUATED : COMPLETE_WITHOUT_UNCONDITIONAL;

View File

@@ -1215,6 +1215,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
@Nullable DfaAnchor instanceofAnchor,
@NotNull PsiType checkType,
@Nullable PsiType patternType) {
checkType = TypeConversionUtil.erasure(checkType);
if (patternType == null ||
(!PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, context) &&
(checkType instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType)) ||

View File

@@ -178,7 +178,7 @@ public final class PatternVariableCanBeUsedInspection extends AbstractBaseJavaLo
if (operand == null) return;
PsiType castType = cast.getCastType().getType();
if (castType instanceof PsiPrimitiveType &&
!JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(PsiUtil.getLanguageLevel(operand))) return;
!PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, operand)) return;
if (!variable.getType().equals(castType)) return;
PsiType operandType = operand.getType();
if (operandType == null || castType.isAssignableFrom(operandType)) return;
@@ -433,7 +433,7 @@ public final class PatternVariableCanBeUsedInspection extends AbstractBaseJavaLo
if (operand == null) return null;
PsiType castType = castTypeElement.getType();
if (castType instanceof PsiPrimitiveType &&
!JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(PsiUtil.getLanguageLevel(operand))) return null;
!PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, operand)) return null;
PsiType operandType = operand.getType();
if (operandType == null || castType.isAssignableFrom(operandType)) return null;
PsiInstanceOfExpression instanceOf = InstanceOfUtils.findPatternCandidate(expression, null);

View File

@@ -260,6 +260,8 @@ default.label.not.allowed.here=Default label not allowed here: 'default' can onl
multiple.switch.labels=Multiple switch labels are permitted for a switch labeled statement group only if none of them declare any pattern variables
switch.dominance.of.preceding.label=Label is dominated by a preceding case label ''{0}''
switch.unconditional.pattern.and.default.exist='switch' has both an unconditional pattern and a default label
switch.unconditional.boolean.and.default.exist='switch' has all boolean values and a default label
switch.unconditional.boolean.and.unconditional.exist='switch' has all boolean values and an unconditional pattern
switch.class.or.array.type.expected=class or array
switch.invalid.selector.types=Selector type of ''{0}'' is not supported
dot.expected.after.super.or.this='.' expected

View File

@@ -205,36 +205,41 @@ public final class JavaPsiPatternUtil {
}
@Contract("null,_,_ -> false")
public static boolean isUnconditionalForType(@Nullable PsiCaseLabelElement pattern, @NotNull PsiType type, boolean forDomination) {
public static boolean isUnconditionalForType(@Nullable PsiCaseLabelElement pattern, @NotNull PsiType type, boolean forDominationOfDeconstructionPatternType) {
PsiPrimaryPattern unconditionalPattern = findUnconditionalPattern(pattern);
if (unconditionalPattern == null) return false;
PsiType patternType = getPatternType(unconditionalPattern);
if (unconditionalPattern instanceof PsiDeconstructionPattern) {
return forDomination && dominates(patternType, type);
return forDominationOfDeconstructionPatternType && dominates(patternType, type);
}
else if ((unconditionalPattern instanceof PsiTypeTestPattern ||
unconditionalPattern instanceof PsiUnnamedPattern) &&
JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(PsiUtil.getLanguageLevel(pattern))) {
if (type instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType) {
if (type.equals(patternType)) return true;
if (type instanceof PsiPrimitiveType && patternType instanceof PsiPrimitiveType) {
return isExactPrimitiveWideningConversion(type, patternType);
}
else if (!(type instanceof PsiPrimitiveType)) {
return false;
}
else {
PsiClassType boxedType = ((PsiPrimitiveType)type).getBoxedType(pattern);
return dominates(boxedType, type);
}
}
else {
return dominates(patternType, type);
}
unconditionalPattern instanceof PsiUnnamedPattern)) {
return isUnconditionallyExactForType(pattern, type, patternType);
}
return false;
}
public static boolean isUnconditionallyExactForType(@NotNull PsiElement context, @NotNull PsiType type, PsiType patternType) {
type = TypeConversionUtil.erasure(type);
if ((type instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType) &&
PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, context)) {
if (type.equals(patternType)) return true;
if (type instanceof PsiPrimitiveType && patternType instanceof PsiPrimitiveType) {
return isExactPrimitiveWideningConversion(type, patternType);
}
else if (!(type instanceof PsiPrimitiveType)) {
return false;
}
else {
PsiClassType boxedType = ((PsiPrimitiveType)type).getBoxedType(context);
return dominates(patternType, boxedType);
}
}
else {
return dominates(patternType, type);
}
}
/**
* Returns the promoted type for a given context, type, and pattern type, according to 5.7.1
*
@@ -336,7 +341,7 @@ public final class JavaPsiPatternUtil {
return true;
}
public static boolean dominates(@Nullable PsiType who, @Nullable PsiType overWhom) {
private static boolean dominates(@Nullable PsiType who, @Nullable PsiType overWhom) {
if (who == null || overWhom == null) return false;
if (who.getCanonicalText().equals(overWhom.getCanonicalText())) return true;
overWhom = TypeConversionUtil.erasure(overWhom);

View File

@@ -51,11 +51,11 @@ public final class JavaPsiSwitchUtil {
}
}
}
return isEnhancedSwitch(cases, isClassSelectorType(selectorType));
return isEnhancedSwitch(cases, selectorType);
}
public static boolean isEnhancedSwitch(@NotNull List<? extends PsiCaseLabelElement> labelElements, boolean selectorIsTypeOrClass) {
if (selectorIsTypeOrClass) return true;
public static boolean isEnhancedSwitch(@NotNull List<? extends PsiCaseLabelElement> labelElements, @NotNull PsiType selectorType) {
if (isEnhancedSelectorType(selectorType)) return true;
return ContainerUtil.exists(labelElements, st -> st instanceof PsiPattern || isNullType(st));
}
@@ -64,7 +64,15 @@ public final class JavaPsiSwitchUtil {
return element instanceof PsiExpression && TypeConversionUtil.isNullType(((PsiExpression)element).getType());
}
private static boolean isClassSelectorType(@NotNull PsiType type) {
private static boolean isEnhancedSelectorType(@NotNull PsiType type) {
PsiPrimitiveType unboxedType = PsiPrimitiveType.getOptionallyUnboxedType(type);
if (unboxedType != null &&
(unboxedType.equals(PsiTypes.booleanType()) ||
unboxedType.equals(PsiTypes.floatType()) ||
unboxedType.equals(PsiTypes.doubleType()) ||
unboxedType.equals(PsiTypes.longType()))) {
return true;
}
if (TypeConversionUtil.getTypeRank(type) <= TypeConversionUtil.INT_RANK) return false;
if (TypeConversionUtil.isPrimitiveAndNotNull(type)) return false;
PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(type);

View File

@@ -0,0 +1,663 @@
package dfa;
public class SwitchRecordPrimitiveIsNotAllowed {
record RecordBool(boolean source) {
}
record RecordInt(int source) {
}
record RecordLong(long source) {
}
record RecordDouble(double source) {
}
record RecordByte(byte source) {
}
record RecordChar(char source) {
}
record RecordBoolObj(Boolean source) {
}
record RecordIntObj(Integer source) {
}
record RecordLongObj(Long source) {
}
record RecordDoubleObj(Double source) {
}
record RecordCharObj(Character source) {
}
record RecordNumber(Number source) {
}
record RecordRecordInt(RecordInt source) {
}
public static void main(String[] args) {
testForRecordBool(new RecordBool(true));
testForRecordBoolObj(new RecordBoolObj(true));
testForRecordChar(new RecordChar('a'));
testForRecordCharObj(new RecordCharObj('a'));
testForRecordByte(new RecordByte((byte) 0));
testForRecordInt(new RecordInt(1));
testForRecordIntObj(new RecordIntObj(1));
testForRecordLong(new RecordLong(1));
testForRecordLongObj(new RecordLongObj(1L));
testForRecordDouble(new RecordDouble(1));
testForRecordDoubleObj(new RecordDoubleObj(1.0));
testForRecordNumber(new RecordNumber(1));
testForRecordRecordInt(new RecordRecordInt(new RecordInt(1)));
}
private static void testForRecordRecordInt(RecordRecordInt source) {
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'boolean', required: 'int'">boolean source1</error>)) -> System.out.println("1"); //error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'char', required: 'int'">char source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'int'">Character source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'char', required: 'int'">char source1</error>)) -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer source1</error>)) -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>)) -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'int'">Number source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>)) -> System.out.println("1");//error
}
}
private static void testForRecordNumber(RecordNumber source) {
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Number'">boolean source1</error>) -> System.out.println("1");//error
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Number'">char source1</error>) -> System.out.println("1");//error
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'java.lang.Number'">Character source1</error>) -> System.out.println("1");//error
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
case RecordNumber(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Number'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
case RecordNumber(Integer source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(Integer source1) -> System.out.println("1");
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordNumber(Object source1) -> System.out.println("1");
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
case RecordNumber(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
case RecordNumber(Number source1) -> System.out.println("1");
case RecordNumber(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
case RecordNumber(Number source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">int source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordDoubleObj(RecordDoubleObj source) {
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Double'">boolean source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Double'">char source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">int source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(Double source1) -> System.out.println("1");
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'float', required: 'java.lang.Double'">float source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Double'">Integer source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordDoubleObj(Object source1) -> System.out.println("1");
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'double', required: 'java.lang.Double'">double source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">int source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Number source1) -> System.out.println("1");
case RecordDoubleObj(Object source1) -> System.out.println("1");
}
}
private static void testForRecordDouble(RecordDouble source) {
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'boolean', required: 'double'">boolean source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'char', required: 'double'">char source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case RecordDouble(<error descr="Incompatible types. Found: 'int', required: 'double'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'int', required: 'double'">int source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Double', required: 'double'">Double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Double', required: 'double'">Double source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'float', required: 'double'">float source1</error>) -> System.out.println("1");//error
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Double', required: 'double'">Double source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'double'">Integer source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'double'">Object source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'double'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(<error descr="Incompatible types. Found: 'int', required: 'double'">int source1</error>) -> System.out.println("1");//error
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'double'">Number source1</error>) -> System.out.println("1");//error
case RecordDouble(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'double'">Object source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordLongObj(RecordLongObj source) {
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Long'">boolean source1</error>) -> System.out.println("1");//error
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Long'">char source1</error>) -> System.out.println("1");//error
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
case RecordLongObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">int source1</error>) -> System.out.println("1");//error
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
case RecordLongObj(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(Long source1) -> System.out.println("1");
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'float', required: 'java.lang.Long'">float source1</error>) -> System.out.println("1");//error
case RecordLongObj(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Long'">Integer source1</error>) -> System.out.println("1");//error
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordLongObj(Object source1) -> System.out.println("1");
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'long', required: 'java.lang.Long'">long source1</error>) -> System.out.println("1");//error
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">int source1</error>) -> System.out.println("1");//error
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(Long source1) -> System.out.println("1");
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'java.lang.Double', required: 'java.lang.Long'">Double source1</error>) -> System.out.println("1");//error
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
}
private static void testForRecordLong(RecordLong source) {
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'boolean', required: 'long'">boolean source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'char', required: 'long'">char source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case RecordLong(<error descr="Incompatible types. Found: 'int', required: 'long'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'int', required: 'long'">int source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Long', required: 'long'">Long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Long', required: 'long'">Long source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'float', required: 'long'">float source1</error>) -> System.out.println("1");//error
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Long', required: 'long'">Long source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'long'">Integer source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'long'">Object source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'long'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLong(<error descr="Incompatible types. Found: 'int', required: 'long'">int source1</error>) -> System.out.println("1");//error
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'long'">Number source1</error>) -> System.out.println("1");//error
case RecordLong(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'long'">Object source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordByte(RecordByte source) {
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'boolean', required: 'byte'">boolean source1</error>) -> System.out.println("1");//error
case RecordByte(<error descr="Incompatible types. Found: 'int', required: 'byte'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(<error descr="Incompatible types. Found: 'int', required: 'byte'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Byte', required: 'byte'">Byte source1</error>) -> System.out.println("1");//error
case RecordByte(<error descr="Incompatible types. Found: 'int', required: 'byte'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'int', required: 'byte'">int source1</error>) -> System.out.println("1");//error
case RecordByte(byte source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'byte'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'byte'">Integer source1</error>) -> System.out.println("1");//error
case RecordByte(byte source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'int', required: 'byte'">int source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'byte'">Object source1</error>) -> System.out.println("1");//error
case RecordByte(byte source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'byte'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case <error descr="Incompatible types. Found: 'dfa.SwitchRecordPrimitiveIsNotAllowed.RecordChar', required: 'dfa.SwitchRecordPrimitiveIsNotAllowed.RecordByte'">RecordChar(Object source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'byte'">Number source1</error>) -> System.out.println("1");//error
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'byte'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'byte'">Object source1</error>) -> System.out.println("1");//error
case RecordByte(byte source1) -> System.out.println("1");
}
}
private static void testForRecordCharObj(RecordCharObj source) {
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Character'">boolean source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(Character source1) -> System.out.println("1");
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Character'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Character'">Integer source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordCharObj(Object source1) -> System.out.println("1");
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Character'">int source1</error>) -> System.out.println("1");//error
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'java.lang.Character'">Number source1</error>) -> System.out.println("1");//error
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(Character source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(Object source1) -> System.out.println("1");
case RecordCharObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Character'">char source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordChar(RecordChar source) {
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'boolean', required: 'char'">boolean source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(char source1) -> System.out.println("1");
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'char'">Character source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
case RecordChar(char source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'char'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'char'">Integer source1</error>) -> System.out.println("1");//error
case RecordChar(char source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char'">Object source1</error>) -> System.out.println("1");//error
case RecordChar(char source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(char source1) -> System.out.println("1");
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'char'">Number source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char'">Object source1</error>) -> System.out.println("1");//error
case RecordChar(<error descr="Incompatible types. Found: 'int', required: 'char'">int source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordInt(RecordInt source) {
switch (source) {
case RecordInt(<error descr="Incompatible types. Found: 'boolean', required: 'int'">boolean source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(<error descr="Incompatible types. Found: 'char', required: 'int'">char source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'int'">Character source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(<error descr="Incompatible types. Found: 'char', required: 'int'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'int'">Number source1</error>) -> System.out.println("1");//error
case RecordInt(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">Object source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordIntObj(RecordIntObj source) {
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Integer'">boolean source1</error>) -> System.out.println("1");//error
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Integer'">char source1</error>) -> System.out.println("1");//error
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'java.lang.Integer'">Character source1</error>) -> System.out.println("1");//error
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
case RecordIntObj(<error descr="Incompatible types. Found: 'char', required: 'java.lang.Integer'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
case RecordIntObj(Integer source1) -> System.out.println("1");
}
switch (source) {
case RecordIntObj(Integer source1) -> System.out.println("1");
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordIntObj(Object source1) -> System.out.println("1");
case RecordIntObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Integer'">int source1</error>) -> System.out.println("1");//error
}
}
private static void testForRecordBool(RecordBool source) {
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
case RecordBool(<error descr="Incompatible types. Found: 'int', required: 'boolean'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
case RecordBool(<error descr="Incompatible types. Found: 'java.lang.Boolean', required: 'boolean'">Boolean source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBool(<error descr="Incompatible types. Found: 'java.lang.Boolean', required: 'boolean'">Boolean source1</error>) -> System.out.println("1");//error
case RecordBool(boolean source1) -> System.out.println("1");
}
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordBool(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'boolean'">Object source1</error>) -> System.out.println("1");//error
case RecordBool(boolean source1) -> System.out.println("1");
}
}
private static void testForRecordBoolObj(RecordBoolObj source) {
switch (source) {
case RecordBoolObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordBoolObj(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Boolean'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBoolObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordBoolObj(Boolean source1) -> System.out.println("1");
}
switch (source) {
case RecordBoolObj(Boolean source1) -> System.out.println("1");
case RecordBoolObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">boolean source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBoolObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">boolean source1</error>) -> System.out.println("1");//error
default -> System.out.println("2");
}
switch (source) {
case RecordBoolObj(Object source1) -> System.out.println("1");
case RecordBoolObj(<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">boolean source1</error>) -> System.out.println("1");//error
}
}
}

View File

@@ -0,0 +1,78 @@
package dfa;
public class SwitchWithPrimitivesNotAllowed {
public static void main(String[] args) {
testPrimitives();
testWrappers();
}
private static void testWrappers() {
Boolean b = true;
switch (b) {
default -> System.out.println("1");
}
Integer i = 1;
switch (i) {
default -> System.out.println("1");
}
Short s = 1;
switch (s) {
default -> System.out.println("1");
}
Byte by = 1;
switch (by) {
default -> System.out.println("1");
}
Character ch = '1';
switch (ch) {
default -> System.out.println("1");
}
Long l = 1L;
switch (l) {
default -> System.out.println("1");
}
Double d = 1.0;
switch (d) {
default -> System.out.println("1");
}
Float f = 1.0F;
switch (f) {
default -> System.out.println("1");
}
}
private static void testPrimitives() {
boolean b = true;
switch (<error descr="Selector type of 'boolean' is not supported">b</error>) {//error
default -> System.out.println("1");
}
int i = 1;
switch (i) {
default -> System.out.println("1");
}
short s = 1;
switch (s) {
default -> System.out.println("1");
}
byte by = 1;
switch (by) {
default -> System.out.println("1");
}
char ch = '1';
switch (ch) {
default -> System.out.println("1");
}
long l = 1L;
switch (<error descr="Selector type of 'long' is not supported">l</error>) { //error
default -> System.out.println("1");
}
double d = 1.0;
switch (<error descr="Selector type of 'double' is not supported">d</error>) {//error
default -> System.out.println("1");
}
float f = 1.0F;
switch (<error descr="Selector type of 'float' is not supported">f</error>) {//error
default -> System.out.println("1");
}
}
}

View File

@@ -0,0 +1,14 @@
package dfa;
public class UnconditionalForSelectTypeAndDominated {
interface AA1{}
interface AA2{}
interface AA extends AA1, AA2{}
interface B {}
private static void testAA(AA aa){
switch (aa) {
case AA1 aa1 -> System.out.println(1);
case <error descr="Label is dominated by a preceding case label 'AA1 aa1'">B aa1</error> -> System.out.println(1);
}
}
}

View File

@@ -0,0 +1,248 @@
package dfa;
public class SwitchConstantPrimitiveAllowed {
public static void main(String[] args) {
testBoolean();
testInt();
testChar();
testByte();
testShort();
testLong();
testFloat();
testDouble();
testBooleanObject();
testIntObject();
testCharObject();
testByteObject();
testShortObject();
testLongObject();
testFloatObject();
testDoubleObject();
}
private static void testDoubleObject() {
Double o = 0.0;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Double'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Double'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Double'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Double'">1.0f</error> -> System.out.println("1.0f"); //error
case 1.0 -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testFloatObject() {
Float o = 1F;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Float'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Float'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Float'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Float'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Float'">1l</error> -> System.out.println("1l"); //error
case 1.0f -> System.out.println("1.0f");
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Float'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testLongObject() {
Long o = 1L;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Long'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Long'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">0xa</error> -> System.out.println("0xa"); //error
case 1l -> System.out.println("1l");
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Long'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Long'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testShortObject() {
Short o = 1;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Short'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Short'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Short'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Short'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testByteObject() {
Byte o = '1';
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Byte'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Byte'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Byte'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Byte'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testCharObject() {
Character o = '1';
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Character'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Character'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Character'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Character'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testIntObject() {
Integer o = 1;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Integer'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Integer'">'a'</error> -> System.out.println("a"); //error
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Integer'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Integer'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Integer'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testBooleanObject() {
Boolean o = true;
switch (o) {
case true -> System.out.println("true");
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Boolean'">1</error> -> System.out.println("1"); //error
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Boolean'">'a'</error> -> System.out.println("a"); //error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Boolean'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Boolean'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Boolean'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Boolean'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testDouble() {
double o = 0.0;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'double'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'double'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'double'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'double'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'double'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'double'">1.0f</error> -> System.out.println("1.0f"); //error
case 1.0 -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testFloat() {
float o = 1F;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'float'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'float'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'float'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'float'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'float'">1l</error> -> System.out.println("1l"); //error
case 1.0f -> System.out.println("1.0f");
case <error descr="Incompatible types. Found: 'double', required: 'float'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testLong() {
long o = 1L;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'long'">true</error> -> System.out.println("true"); //error
case <error descr="Incompatible types. Found: 'int', required: 'long'">1</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'char', required: 'long'">'a'</error> -> System.out.println("a");//error
case <error descr="Incompatible types. Found: 'int', required: 'long'">0xa</error> -> System.out.println("0xa"); //error
case 1l -> System.out.println("1l");
case <error descr="Incompatible types. Found: 'float', required: 'long'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'long'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testShort() {
short o = 1;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'short'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'short'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'short'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'short'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testByte() {
byte o = '1';
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'byte'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'byte'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'byte'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'byte'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testChar() {
char o = '1';
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'char'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'char'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'char'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'char'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testInt() {
int o = 1;
switch (o) {
case <error descr="Incompatible types. Found: 'boolean', required: 'int'">true</error> -> System.out.println("true"); //error
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
case <error descr="Incompatible types. Found: 'long', required: 'int'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'int'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'int'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
private static void testBoolean() {
boolean o = true;
switch (o) {
case true -> System.out.println("true");
case <error descr="Incompatible types. Found: 'int', required: 'boolean'">1</error> -> System.out.println("1"); //error
case <error descr="Incompatible types. Found: 'char', required: 'boolean'">'a'</error> -> System.out.println("a"); //error
case <error descr="Incompatible types. Found: 'int', required: 'boolean'">0xa</error> -> System.out.println("0xa"); //error
case <error descr="Incompatible types. Found: 'long', required: 'boolean'">1l</error> -> System.out.println("1l"); //error
case <error descr="Incompatible types. Found: 'float', required: 'boolean'">1.0f</error> -> System.out.println("1.0f"); //error
case <error descr="Incompatible types. Found: 'double', required: 'boolean'">1.0</error> -> System.out.println("1.0f"); //error
default -> System.out.println("default");
}
}
}

View File

@@ -0,0 +1,297 @@
package dfa;
public class SwitchConstantPrimitiveSimilar {
public static final long LONG = 2L + 3L;
private static final Long LONG_OBJECT = LONG;
public static void main(String[] args) {
testBoolean();
testInt();
testChar();
testByte();
testShort();
testLong();
testFloat();
testDouble();
testBooleanObject();
testIntObject();
testCharObject();
testByteObject();
testShortObject();
testLongObject();
testFloatObject();
testDoubleObject();
}
private static void testDouble() {
double o = 0.0;
switch (o) {
case <error descr="Duplicate label '1'">1.0</error> -> System.out.println("1.0f");
case <error descr="Duplicate label '1'">1.0</error> -> System.out.println("1.0f"); // error
default -> System.out.println("default");
}
switch (o) {
case 1.0 -> System.out.println("1.0f");
case 2.0 -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testFloat() {
float o = 1F;
switch (o) {
case <error descr="Duplicate label '1'">1.0f</error> -> System.out.println("1.0f");
case <error descr="Duplicate label '1'">1.0f</error> -> System.out.println("1.0f");// error
default -> System.out.println("default");
}
switch (o) {
case 1.0f -> System.out.println("1.0f");
case 2.0f -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testLong() {
long o = 1L;
switch (o) {
case <error descr="Duplicate label '1'">1L</error> -> System.out.println("1l");
case <error descr="Duplicate label '1'">1L</error> -> System.out.println("1l");// error
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case 2L -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case 2L + 3L -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case LONG -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case <error descr="Constant expression required">LONG_OBJECT</error> -> System.out.println("1l");// error
default -> System.out.println("default");
}
}
private static void testShort() {
short o = 1;
switch (o) {
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 2 -> System.out.println("1");
case 1 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testByte() {
byte o = '1';
switch (o) {
case 1 -> System.out.println("1");
case <error descr="Duplicate label '97'">'a'</error> -> System.out.println("a");
case <error descr="Duplicate label '97'">'a'</error> -> System.out.println("a");// error
case 0xa -> System.out.println("0xa");
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 'b' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
default -> System.out.println("default");
}
}
private static void testChar() {
char o = '1';
switch (o) {
case <error descr="Duplicate label ''">1</error> -> System.out.println("1");
case <error descr="Duplicate label ''">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 2 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testInt() {
int o = 1;
switch (o) {
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 2 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testBoolean() {
boolean o = true;
switch (o) {
case <error descr="Duplicate label 'true'">true</error> -> System.out.println("true");
case <error descr="Duplicate label 'true'">true</error> -> System.out.println("true");// error
default -> System.out.println("default");
}
switch (o) {
case false -> System.out.println("true");
case true -> System.out.println("true");
}
switch (o) {
case <error descr="Constant expression required">Boolean.TRUE</error> -> System.out.println("true");// error
case true -> System.out.println("true");
}
}
private static void testDoubleObject() {
Double o = 0.0;
switch (o) {
case <error descr="Duplicate label '1'">1.0</error> -> System.out.println("1.0f");
case <error descr="Duplicate label '1'">1.0</error> -> System.out.println("1.0f");// error
default -> System.out.println("default");
}
switch (o) {
case 1.0 -> System.out.println("1.0f");
case 2.0 -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testFloatObject() {
Float o = 1F;
switch (o) {
case <error descr="Duplicate label '1'">1.0f</error> -> System.out.println("1.0f");
case <error descr="Duplicate label '1'">1.0f</error> -> System.out.println("1.0f");// error
default -> System.out.println("default");
}
switch (o) {
case 1.0f -> System.out.println("1.0f");
case 2.0f -> System.out.println("1.0f");
default -> System.out.println("default");
}
}
private static void testLongObject() {
Long o = 1L;
switch (o) {
case <error descr="Duplicate label '1'">1L</error> -> System.out.println("1l");
case <error descr="Duplicate label '1'">1L</error> -> System.out.println("1l");// error
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case 2L -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case 2L + 3L -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case LONG -> System.out.println("1l");
default -> System.out.println("default");
}
switch (o) {
case 1L -> System.out.println("1l");
case <error descr="Constant expression required">LONG_OBJECT</error> -> System.out.println("1l");// error
default -> System.out.println("default");
}
}
private static void testShortObject() {
Short o = 1;
switch (o) {
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 2 -> System.out.println("1");
case 1 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testByteObject() {
Byte o = '1';
switch (o) {
case 1 -> System.out.println("1");
case <error descr="Duplicate label '97'">'a'</error> -> System.out.println("a");
case <error descr="Duplicate label '97'">'a'</error> -> System.out.println("a");// error
case 0xa -> System.out.println("0xa");
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 'a' -> System.out.println("a");
case 'b' -> System.out.println("a");
case 0xa -> System.out.println("0xa");
default -> System.out.println("default");
}
}
private static void testCharObject() {
Character o = '1';
switch (o) {
case <error descr="Duplicate label ''">1</error> -> System.out.println("1");
case <error descr="Duplicate label ''">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 2 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testIntObject() {
Integer o = 1;
switch (o) {
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");
case <error descr="Duplicate label '1'">1</error> -> System.out.println("1");// error
default -> System.out.println("default");
}
switch (o) {
case 1 -> System.out.println("1");
case 2 -> System.out.println("1");
default -> System.out.println("default");
}
}
private static void testBooleanObject() {
Boolean o = true;
switch (o) {
case <error descr="Duplicate label 'true'">true</error> -> System.out.println("true");
case <error descr="Duplicate label 'true'">true</error> -> System.out.println("true");// error
default -> System.out.println("default");
}
switch (o) {
case false -> System.out.println("true");
case true -> System.out.println("true");
}
switch (o) {
case <error descr="Constant expression required">Boolean.TRUE</error> -> System.out.println("true");// error
case true -> System.out.println("true");
}
}
}

View File

@@ -0,0 +1,416 @@
package dfa;
public class SwitchPrimitiveCompleteness {
public static void main(String[] args) {
withErasureSwitch(1);
testBoolean();
testChar();
testInt();
testLong();
testFloat();
testDouble();
testBooleanObject();
testCharObject();
testIntObject();
testLongObject();
testFloatObject();
testDoubleObject();
testNumber();
testObject();
}
public static <T extends Integer> boolean withErasureSwitch(T i) {
return switch (i) {
case long a -> false;
};
}
private static void testObject() {
Object d = 0.0;
switch (d) {
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Object'">1</error> -> System.out.println("1"); //error
case double ob -> System.out.println("1");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Object'">2.0</error> -> System.out.println("1"); //error
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Object'">2.0</error> -> System.out.println("1"); //error
case Double ob -> System.out.println("1");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Object'">2.0</error> -> System.out.println("1"); //error
case Double ob -> System.out.println("1");
default -> System.out.println("2");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Object'">2.0</error> -> System.out.println("1"); //error
case Object a -> System.out.println("2");
}
}
private static void testNumber() {
Number d = 0.0;
switch (d) {
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Number'">1</error> -> System.out.println("1"); //error
case double ob -> System.out.println("1");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Number'">2.0</error> -> System.out.println("1"); //error
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Number'">2.0</error> -> System.out.println("1"); //error
case Double ob -> System.out.println("1");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Number'">2.0</error> -> System.out.println("1"); //error
case Double ob -> System.out.println("1");
default -> System.out.println("2");
}
switch (d) {
case <error descr="Incompatible types. Found: 'double', required: 'java.lang.Number'">2.0</error> -> System.out.println("1"); //error
case Object a -> System.out.println("2");
}
}
private static void testDoubleObject() {
Double d = 0.0;
switch (d) {
case 0.1 -> System.out.println("1");
case double ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">d</error>) { //error
case 2.0 -> System.out.println("1");
}
switch (d) {
case 2.0 -> System.out.println("1");
case Double ob -> System.out.println("1");
}
switch (d) {
case 2.0 -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Double ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (d) {
case 2.0 -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testDouble() {
double d = 0.0;
switch (d) {
case 0.1 -> System.out.println("1");
case double ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">d</error>) { //error
case 2.0 -> System.out.println("1");
}
switch (d) {
case 2.0 -> System.out.println("1");
case Double ob -> System.out.println("1");
}
switch (d) {
case 2.0 -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Double ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (d) {
case 2.0 -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testFloat() {
float f = 0.0F;
switch (f) {
case 2.0F -> System.out.println("1");
case float ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">f</error>) { //error
case 2.0F -> System.out.println("1");
}
switch (f) {
case 2.0F -> System.out.println("1");
case Float ob -> System.out.println("1");
}
switch (f) {
case 2.0F -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Float ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (f) {
case 2.0F -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testFloatObject() {
Float f = 0.0F;
switch (f) {
case 2.0F -> System.out.println("1");
case float ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">f</error>) {
case 2.0F -> System.out.println("1");
}
switch (f) {
case 2.0F -> System.out.println("1");
case Float ob -> System.out.println("1");
}
switch (f) {
case 2.0F -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Float ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (f) {
case 2.0F -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testLongObject() {
Long l = 1L;
switch (l) {
case 2L -> System.out.println("1");
case long ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">l</error>) {
case 1L -> System.out.println("1");
}
switch (l) {
case 3L -> System.out.println("1");
case Long ob -> System.out.println("1");
}
switch (l) {
case 3L -> System.out.println("1");
case <error descr="Incompatible types. Found: 'java.lang.Double', required: 'java.lang.Long'">Double ob</error> -> System.out.println("1"); //error
default -> System.out.println("2");
}
switch (l) {
case 1L -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testLong() {
long l = 1L;
switch (l) {
case 2L -> System.out.println("1");
case long ob -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">l</error>) { //error
case 1L -> System.out.println("1");
}
switch (l) {
case 3L -> System.out.println("1");
case Long ob -> System.out.println("1");
}
switch (l) {
case 3L -> System.out.println("1");
case <error descr="Incompatible types. Found: 'java.lang.Double', required: 'long'">Double ob</error> -> System.out.println("1"); //error
default -> System.out.println("2");
}
switch (l) {
case 1L -> System.out.println("1");
case long a -> System.out.println("2");
}
switch (l) {
case 1L -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testIntObject() {
Integer i = 1;
switch (i) {
case 2 -> System.out.println("1");
case int ob -> System.out.println("1");
}
switch (i) {
case 1 -> System.out.println("1");
}
switch (i) {
case 3 -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Integer ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (i) {
case 1 -> System.out.println("1");
case Integer a -> System.out.println("2");
}
switch (i) {
case 1 -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testInt() {
int i = 1;
switch (i) {
case 2 -> System.out.println("1");
case int ob -> System.out.println("1");
}
switch (i) {
case 1 -> System.out.println("1");
}
switch (i) {
case 3 -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Integer ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (i) {
case 1 -> System.out.println("1");
case Integer a -> System.out.println("2");
}
switch (i) {
case 1 -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testCharObject() {
Character b = 'a';
switch (b) {
case 'a' -> System.out.println("1");
case char ob -> System.out.println("1");
}
switch (b) {
case 'a' -> System.out.println("1");
}
switch (b) {
case 'a' -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Character ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (b) {
case 'a' -> System.out.println("1");
case Character a -> System.out.println("2");
}
switch (b) {
case 'a' -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testChar() {
char b = 'a';
switch (b) {
case 'a' -> System.out.println("1");
case char ob -> System.out.println("1");
}
switch (b) {
case 'a' -> System.out.println("1");
}
switch (b) {
case 'a' -> System.out.println("1");
case <error descr="'switch' has both an unconditional pattern and a default label">Character ob</error> -> System.out.println("1"); //error
<error descr="'switch' has both an unconditional pattern and a default label">default</error> -> System.out.println("2"); //error
}
switch (b) {
case 'a' -> System.out.println("1");
case Character a -> System.out.println("2");
}
switch (b) {
case 'a' -> System.out.println("1");
case Object a -> System.out.println("2");
}
}
private static void testBooleanObject() {
Boolean b = true;
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">b</error>) { //error
case false -> System.out.println("1");
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
<error descr="'switch' has all boolean values and a default label">default</error> -> System.out.println("2"); //error
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case <error descr="'switch' has all boolean values and an unconditional pattern">Boolean a</error> -> System.out.println("2"); //error
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case boolean a -> System.out.println("2");
}
switch (b) {
case false -> System.out.println("1");
case boolean a -> System.out.println("2");
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case <error descr="'switch' has all boolean values and an unconditional pattern">Object a</error> -> System.out.println("2"); //error
}
}
private static void testBoolean() {
boolean b = true;
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">b</error>) { //error
case false -> System.out.println("1");
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
<error descr="'switch' has all boolean values and a default label">default</error> -> System.out.println("2"); //error
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case <error descr="'switch' has all boolean values and an unconditional pattern">Boolean a</error> -> System.out.println("2"); //error
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case <error descr="'switch' has all boolean values and an unconditional pattern">boolean a</error> -> System.out.println("2"); //error
}
switch (b) {
case false -> System.out.println("1");
case boolean a -> System.out.println("2");
}
switch (b) {
case true -> System.out.println("1");
case false -> System.out.println("1");
case <error descr="'switch' has all boolean values and an unconditional pattern">Object a</error> -> System.out.println("2"); //error
}
}
}

View File

@@ -0,0 +1,206 @@
package dfa;
public class SwitchPrimitivePatternList {
public static void main(String[] args) {
testChar();
testByte();
testShort();
testInt();
testLong();
testFloat();
testDouble();
testCharObject();
testByteObject();
testShortObject();
testIntObject();
testLongObject();
testFloatObject();
testDoubleObject();
}
private static void testCharObject() {
Character i = 0;
switch (i) {
case char d -> System.out.println("1");
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Character'">byte d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'short', required: 'java.lang.Character'">short d</error> -> System.out.println("1");//error
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testByteObject() {
Byte i = 0;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Byte'">char d</error> -> System.out.println("1");//error
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testShortObject() {
Short i = 0;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Short'">char d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Short'">byte d</error> -> System.out.println("1");//error
case short d -> System.out.println("1");
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testIntObject() {
Integer i = 0;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Integer'">char d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Integer'">byte d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'short', required: 'java.lang.Integer'">short d</error> -> System.out.println("1");//error
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testLongObject() {
Long i = 0L;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Long'">char d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Long'">byte d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'short', required: 'java.lang.Long'">short d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">int d</error> -> System.out.println("1");//error
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testFloatObject() {
Float i = 0F;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Float'">char d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Float'">byte d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'short', required: 'java.lang.Float'">short d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Float'">int d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Float'">long d</error> -> System.out.println("1");//error
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
private static void testDoubleObject() {
Double i = 0.0;
switch (i) {
case <error descr="Incompatible types. Found: 'char', required: 'java.lang.Double'">char d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'byte', required: 'java.lang.Double'">byte d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'short', required: 'java.lang.Double'">short d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'int', required: 'java.lang.Double'">int d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'long', required: 'java.lang.Double'">long d</error> -> System.out.println("1");//error
case <error descr="Incompatible types. Found: 'float', required: 'java.lang.Double'">float d</error> -> System.out.println("1");//error
case double d -> System.out.println("1");
}
}
private static void testChar() {
char i = 0;
switch (i) {
case <error descr="Duplicate unconditional pattern">char d</error> -> System.out.println("1");//error
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">int d</error> -> System.out.println("1"); //error
case <error descr="Duplicate unconditional pattern">long d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">float d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">double d</error> -> System.out.println("1");//error
}
}
private static void testByte() {
byte i = 0;
switch (i) {
case char d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">byte d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">short d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">int d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">long d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">float d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">double d</error> -> System.out.println("1");//error
}
}
private static void testShort() {
short i = 0;
switch (i) {
case char d -> System.out.println("1");
case byte d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">short d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">int d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">long d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">float d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">double d</error> -> System.out.println("1");//error
}
}
private static void testInt() {
int i = 0;
switch (i) {
case char d -> System.out.println("1");
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">int d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">long d</error> -> System.out.println("1");//error
case float d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">double d</error> -> System.out.println("1");//error
}
}
private static void testLong() {
long i = 0;
switch (i) {
case char d -> System.out.println("1");
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'long d'">float d</error> -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'long d'">double d</error> -> System.out.println("1");
}
}
private static void testFloat() {
float i = 0;
switch (i) {
case char d -> System.out.println("1");
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case <error descr="Duplicate unconditional pattern">float d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">double d</error> -> System.out.println("1");//error
case <error descr="Duplicate unconditional pattern">Float f</error> -> System.out.println();//error
}
}
private static void testDouble() {
double i = 0;
switch (i) {
case char d -> System.out.println("1");
case byte d -> System.out.println("1");
case short d -> System.out.println("1");
case int d -> System.out.println("1");
case long d -> System.out.println("1");
case float d -> System.out.println("1");
case double d -> System.out.println("1");
}
}
}

View File

@@ -0,0 +1,680 @@
package dfa;
public class SwitchRecordPrimitive {
record RecordBool(boolean source) {
}
record RecordInt(int source) {
}
record RecordLong(long source) {
}
record RecordDouble(double source) {
}
record RecordByte(byte source) {
}
record RecordChar(char source) {
}
record RecordBoolObj(Boolean source) {
}
record RecordIntObj(Integer source) {
}
record RecordLongObj(Long source) {
}
record RecordDoubleObj(Double source) {
}
record RecordCharObj(Character source) {
}
record RecordNumber(Number source) {
}
record RecordRecordInt(RecordInt source) {
}
public static void main(String[] args) {
testForRecordBool(new RecordBool(true));
testForRecordBoolObj(new RecordBoolObj(true));
testForRecordChar(new RecordChar('a'));
testForRecordCharObj(new RecordCharObj('a'));
testForRecordByte(new RecordByte((byte) 0));
testForRecordInt(new RecordInt(1));
testForRecordIntObj(new RecordIntObj(1));
testForRecordLong(new RecordLong(1));
testForRecordLongObj(new RecordLongObj(1L));
testForRecordDouble(new RecordDouble(1));
testForRecordDoubleObj(new RecordDoubleObj(1.0));
testForRecordNumber(new RecordNumber(1));
testForRecordRecordInt(new RecordRecordInt(new RecordInt(1)));
exhaustiveByPrimitives();
}
public static int exhaustiveByPrimitives() {
RecordIntObj r = new RecordIntObj(1);
switch (r) {
case RecordIntObj(int x) -> System.out.println("1");
}
switch (r) {
case RecordIntObj(double x) -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">r</error>) { //error
case RecordIntObj(float x) -> System.out.println("1");
}
return 1;
}
private static void testForRecordRecordInt(RecordRecordInt source) {
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Inconvertible types; cannot cast 'int' to 'boolean'">boolean source1</error>)) -> System.out.println("1"); //error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(char source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(<error descr="Inconvertible types; cannot cast 'int' to 'java.lang.Character'">Character source1</error>)) -> System.out.println("1");//error
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordRecordInt(RecordInt(int source1))'">RecordRecordInt(RecordInt(char source1))</error> -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(Integer source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(Integer source1)) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordRecordInt(RecordInt(Integer source1))'">RecordRecordInt(RecordInt(int source1))</error> -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordRecordInt(RecordInt(Object source1)) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordRecordInt(RecordInt(Object source1))'">RecordRecordInt(RecordInt(int source1))</error> -> System.out.println("1");//error
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(Object source1)) -> System.out.println("1");
}
switch (source) {
case RecordRecordInt(RecordInt(int source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(Number source1)) -> System.out.println("1");
case RecordRecordInt(RecordInt(Object source1)) -> System.out.println("1");
}
}
private static void testForRecordNumber(RecordNumber source) {
switch (source) {
case RecordNumber(<error descr="Inconvertible types; cannot cast 'java.lang.Number' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordNumber(int source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(<error descr="Inconvertible types; cannot cast 'java.lang.Number' to 'char'">char source1</error>) -> System.out.println("1");//error
case RecordNumber(int source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'java.lang.Number'">Character source1</error>) -> System.out.println("1");//error
case RecordNumber(int source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(int source1) -> System.out.println("1");
case RecordNumber(<error descr="Inconvertible types; cannot cast 'java.lang.Number' to 'char'">char source1</error>) -> System.out.println("1");//error
}
switch (<error descr="'switch' statement does not cover all possible input values">source</error>) {//error
case RecordNumber(int source1) -> System.out.println("1");
case RecordNumber(Integer source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(Integer source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordNumber(Integer source1)'">RecordNumber(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordNumber(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordNumber(Object source1)'">RecordNumber(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordNumber(int source1) -> System.out.println("1");
case RecordNumber(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(int source1) -> System.out.println("1");
case RecordNumber(Number source1) -> System.out.println("1");
case RecordNumber(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordNumber(int source1) -> System.out.println("1");
case RecordNumber(Number source1) -> System.out.println("1");
}
switch (<error descr="'switch' statement does not cover all possible input values">source</error>) {//error
case RecordNumber(int source1) -> System.out.println("1");
}
}
private static void testForRecordDoubleObj(RecordDoubleObj source) {
switch (source) {
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'char'">char source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(double source1) -> System.out.println("1");
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'int'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'int'">int source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(double source1) -> System.out.println("1");
case RecordDoubleObj(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(Double source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordDoubleObj(Double source1)'">RecordDoubleObj(double source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'float'">float source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Double'">Integer source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(double source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordDoubleObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordDoubleObj(Object source1)'">RecordDoubleObj(double source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordDoubleObj(double source1) -> System.out.println("1");
case RecordDoubleObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordDoubleObj(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'int'">int source1</error>) -> System.out.println("1");//error
case RecordDoubleObj(Number source1) -> System.out.println("1");
case RecordDoubleObj(Object source1) -> System.out.println("1");
}
}
private static void testForRecordDouble(RecordDouble source) {
switch (source) {
case RecordDouble(<error descr="Inconvertible types; cannot cast 'double' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(char source1) -> System.out.println("1");
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordDouble(double source1)'">RecordDouble(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(int source1) -> System.out.println("1");
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case RecordDouble(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(Double source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordDouble(Double source1)'">RecordDouble(double source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(float source1) -> System.out.println("1");
case RecordDouble(Double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(<error descr="Inconvertible types; cannot cast 'double' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
case RecordDouble(double source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordDouble(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordDouble(Object source1)'">RecordDouble(double source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordDouble(double source1) -> System.out.println("1");
case RecordDouble(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordDouble(int source1) -> System.out.println("1");
case RecordDouble(Number source1) -> System.out.println("1");
case RecordDouble(Object source1) -> System.out.println("1");
}
}
private static void testForRecordLongObj(RecordLongObj source) {
switch (source) {
case RecordLongObj(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordLongObj(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'char'">char source1</error>) -> System.out.println("1");//error
case RecordLongObj(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(long source1) -> System.out.println("1");
case RecordLongObj(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">int source1</error>) -> System.out.println("1");//error
case RecordLongObj(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(long source1) -> System.out.println("1");
case RecordLongObj(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(Long source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordLongObj(Long source1)'">RecordLongObj(long source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(float source1) -> System.out.println("1");
case RecordLongObj(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Long'">Integer source1</error>) -> System.out.println("1");//error
case RecordLongObj(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(long source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordLongObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordLongObj(Object source1)'">RecordLongObj(long source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordLongObj(long source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">int source1</error>) -> System.out.println("1");//error
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(Long source1) -> System.out.println("1");
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLongObj(<error descr="Incompatible types. Found: 'java.lang.Double', required: 'java.lang.Long'">Double source1</error>) -> System.out.println("1");//error
case RecordLongObj(Number source1) -> System.out.println("1");
case RecordLongObj(Object source1) -> System.out.println("1");
}
}
private static void testForRecordLong(RecordLong source) {
switch (source) {
case RecordLong(<error descr="Inconvertible types; cannot cast 'long' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(char source1) -> System.out.println("1");
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordLong(long source1)'">RecordLong(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordLong(int source1) -> System.out.println("1");
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case RecordLong(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(Long source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordLong(Long source1)'">RecordLong(long source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordLong(float source1) -> System.out.println("1");
case RecordLong(Long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(<error descr="Inconvertible types; cannot cast 'long' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
case RecordLong(long source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordLong(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordLong(Object source1)'">RecordLong(long source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordLong(long source1) -> System.out.println("1");
case RecordLong(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordLong(int source1) -> System.out.println("1");
case RecordLong(Number source1) -> System.out.println("1");
case RecordLong(Object source1) -> System.out.println("1");
}
}
private static void testForRecordByte(RecordByte source) {
switch (source) {
case RecordByte(<error descr="Inconvertible types; cannot cast 'byte' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordByte(int source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(int source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(Byte source1) -> System.out.println("1");
case RecordByte(int source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(int source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordByte(int source1)'">RecordByte(byte source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(<error descr="Inconvertible types; cannot cast 'byte' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordByte(<error descr="Inconvertible types; cannot cast 'byte' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
case RecordByte(byte source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordByte(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordByte(Object source1)'">RecordByte(byte source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case <error descr="Incompatible types. Found: 'dfa.SwitchRecordPrimitive.RecordChar', required: 'dfa.SwitchRecordPrimitive.RecordByte'">RecordChar(Object source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordByte(byte source1) -> System.out.println("1");
case RecordByte(Number source1) -> System.out.println("1");
case RecordByte(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordByte(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordByte(Object source1)'">RecordByte(byte source1)</error> -> System.out.println("1");//error
}
}
private static void testForRecordCharObj(RecordCharObj source) {
switch (source) {
case RecordCharObj(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordCharObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(char source1) -> System.out.println("1");
case RecordCharObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(Character source1) -> System.out.println("1");
case RecordCharObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(int source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordCharObj(int source1)'">RecordCharObj(char source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(int source1) -> System.out.println("1");
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Character'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.Character'">Integer source1</error>) -> System.out.println("1");//error
case RecordCharObj(char source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordCharObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordCharObj(Object source1)'">RecordCharObj(char source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordCharObj(char source1) -> System.out.println("1");
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(int source1) -> System.out.println("1");
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(char source1) -> System.out.println("1");
case RecordCharObj(<error descr="Incompatible types. Found: 'java.lang.Number', required: 'java.lang.Character'">Number source1</error>) -> System.out.println("1");//error
case RecordCharObj(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(Character source1) -> System.out.println("1");
}
switch (source) {
case RecordCharObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordCharObj(Object source1)'">RecordCharObj(char source1)</error> -> System.out.println("1");//error
}
}
private static void testForRecordChar(RecordChar source) {
switch (source) {
case RecordChar(<error descr="Inconvertible types; cannot cast 'char' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordChar(int source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(char source1) -> System.out.println("1");
case RecordChar(int source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(Character source1) -> System.out.println("1");
case RecordChar(int source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(int source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordChar(int source1)'">RecordChar(char source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordChar(int source1) -> System.out.println("1");
case RecordChar(<error descr="Inconvertible types; cannot cast 'char' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordChar(<error descr="Inconvertible types; cannot cast 'char' to 'java.lang.Integer'">Integer source1</error>) -> System.out.println("1");//error
case RecordChar(char source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordChar(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordChar(Object source1)'">RecordChar(char source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordChar(char source1) -> System.out.println("1");
case RecordChar(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(int source1) -> System.out.println("1");
case RecordChar(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(int source1) -> System.out.println("1");
case RecordChar(<error descr="Inconvertible types; cannot cast 'char' to 'java.lang.Number'">Number source1</error>) -> System.out.println("1");//error
case RecordChar(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordChar(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordChar(Object source1)'">RecordChar(int source1)</error> -> System.out.println("1");//error
}
}
private static void testForRecordInt(RecordInt source) {
switch (source) {
case RecordInt(<error descr="Inconvertible types; cannot cast 'int' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(char source1) -> System.out.println("1");
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(<error descr="Inconvertible types; cannot cast 'int' to 'java.lang.Character'">Character source1</error>) -> System.out.println("1");//error
case RecordInt(int source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordInt(int source1)'">RecordInt(char source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(Integer source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(Integer source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordInt(Integer source1)'">RecordInt(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordInt(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordInt(Object source1)'">RecordInt(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(Object source1) -> System.out.println("1");
}
switch (source) {
case RecordInt(int source1) -> System.out.println("1");
case RecordInt(Number source1) -> System.out.println("1");
case RecordInt(Object source1) -> System.out.println("1");
}
}
private static void testForRecordIntObj(RecordIntObj source) {
switch (source) {
case RecordIntObj(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'boolean'">boolean source1</error>) -> System.out.println("1");//error
case RecordIntObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordIntObj(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'char'">char source1</error>) -> System.out.println("1");//error
case RecordIntObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordIntObj(<error descr="Incompatible types. Found: 'java.lang.Character', required: 'java.lang.Integer'">Character source1</error>) -> System.out.println("1");//error
case RecordIntObj(int source1) -> System.out.println("1");
}
switch (source) {
case RecordIntObj(int source1) -> System.out.println("1");
case RecordIntObj(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'char'">char source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(int source1) -> System.out.println("1");
case RecordIntObj(Integer source1) -> System.out.println("1");
}
switch (source) {
case RecordIntObj(Integer source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordIntObj(Integer source1)'">RecordIntObj(int source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordIntObj(int source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordIntObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordIntObj(Object source1)'">RecordIntObj(int source1)</error> -> System.out.println("1");//error
}
}
private static void testForRecordBool(RecordBool source) {
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
case RecordBool(<error descr="Inconvertible types; cannot cast 'boolean' to 'int'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
case RecordBool(Boolean source1) -> System.out.println("1");
}
switch (source) {
case RecordBool(Boolean source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordBool(Boolean source1)'">RecordBool(boolean source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordBool(boolean source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordBool(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordBool(Object source1)'">RecordBool(boolean source1)</error> -> System.out.println("1");//error
}
}
private static void testForRecordBoolObj(RecordBoolObj source) {
switch (source) {
case RecordBoolObj(boolean source1) -> System.out.println("1");
case RecordBoolObj(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'int'">int source1</error>) -> System.out.println("1");//error
}
switch (source) {
case RecordBoolObj(boolean source1) -> System.out.println("1");
case RecordBoolObj(Boolean source1) -> System.out.println("1");
}
switch (source) {
case RecordBoolObj(Boolean source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordBoolObj(Boolean source1)'">RecordBoolObj(boolean source1)</error> -> System.out.println("1");//error
}
switch (source) {
case RecordBoolObj(boolean source1) -> System.out.println("1");
default -> System.out.println("2");
}
switch (source) {
case RecordBoolObj(Object source1) -> System.out.println("1");
case <error descr="Label is dominated by a preceding case label 'RecordBoolObj(Object source1)'">RecordBoolObj(boolean source1)</error> -> System.out.println("1");//error
}
}
}

View File

@@ -3,6 +3,25 @@ package dfa;
public class SwitchWithPrimitive {
public static void main(String[] args) {
testTestPattern(2L);
System.out.println(withErasureSwitch(1));
System.out.println(exhaustiveByPrimitives(new RecordCharObj('1')));
}
public static int exhaustiveByPrimitives(RecordCharObj source) {
switch (source) {
case RecordCharObj(char source1) -> System.out.println("1");
case <warning descr="Switch label 'RecordCharObj(int source1)' is unreachable">RecordCharObj(int source1)</warning> -> System.out.println("1");
}
return 1;
}
record RecordCharObj(Character x) {
}
public static <T extends Integer> boolean withErasureSwitch(T i) {
return <warning descr="Condition 'switch (i) { case long a -> false; }' is always 'false'">switch (i) {
case <warning descr="Switch label 'long a' is the only reachable in the whole switch">long a</warning> -> false;
}</warning>;
}
private static void testTestPattern(Long l2) {

View File

@@ -199,6 +199,18 @@ public class LightPatternsForSwitchHighlightingTest extends LightJavaCodeInsight
doTest();
}
public void testSwitchWithPrimitivesNotAllowed() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22, this::doTest);
}
public void testSwitchRecordPrimitiveIsNotAllowed() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22, this::doTest);
}
public void testUnconditionalForSelectTypeAndDominated() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
}
private void doTest() {
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.checkHighlighting();

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class LightPrimitivePatternsHighlightingTest extends LightJavaCodeInsightFixtureTestCase {
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns";
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advHighlightingPatternsWithPrimitives";
}
@NotNull
@@ -31,6 +31,20 @@ public class LightPrimitivePatternsHighlightingTest extends LightJavaCodeInsight
doTest();
}
public void testSwitchConstantPrimitiveAllowed() { doTest(); }
public void testSwitchConstantPrimitiveSimilar() { doTest(); }
public void testSwitchPrimitivePatternList() { doTest(); }
public void testSwitchPrimitivePatternApplicable() { doTest(); }
public void testSwitchPrimitivePatternDominated() { doTest(); }
public void testSwitchPrimitiveCompleteness() { doTest(); }
public void testSwitchRecordPrimitive() { doTest(); }
private void doTest() {
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.checkHighlighting();