From cd24adac32803ec39281274d332a5d9c664b27c1 Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Mon, 1 May 2017 08:27:25 +0200 Subject: [PATCH] Detect redundant 'is' check #KT-14187 Fixed --- .../jetbrains/kotlin/diagnostics/Errors.java | 2 ++ .../rendering/DefaultErrorMessages.java | 1 + .../PatternMatchingTypingVisitor.kt | 20 ++++++++++++++---- .../diagnostics/tests/EnumEntryAsType.kt | 4 ++-- .../diagnostics/tests/IsExpressions.kt | 21 ++++++++++++++++++- .../diagnostics/tests/IsExpressions.txt | 11 ++++++++++ .../diagnostics/tests/LValueAssignment.kt | 2 +- .../tests/NumberPrefixAndSuffix.kt | 4 ++-- .../tests/StringPrefixAndSuffix.kt | 3 ++- .../tests/annotations/ConstructorCall.kt | 2 +- .../IsErasedAllowForExactSupertypeCheck.kt | 2 +- ...AllowForSupertypeCheckWithContrvariance.kt | 2 +- ...sedAllowForSupertypeCheckWithCovariance.kt | 2 +- .../tests/cast/IsErasedAllowFromOut.kt | 2 +- .../tests/cast/IsErasedAllowFromOut2.kt | 2 +- .../tests/cast/IsErasedAllowFromOutAtClass.kt | 2 +- .../diagnostics/tests/cast/IsErasedTasT.kt | 2 +- .../tests/cast/IsErasedUpcastToNonReified.kt | 16 +++++++------- .../tests/cast/checkCastToNullableType.kt | 14 ++++++------- .../UninitializedOrReassignedVariables.kt | 2 +- .../controlStructures/when.kt234.kt973.kt | 2 +- .../dataFlowInfoTraversal/IsExpression.kt | 2 +- .../tests/dataFlowInfoTraversal/ManyIfs.kt | 10 ++++----- .../generics/innerClasses/bareTypesComplex.kt | 2 +- .../diagnostics/tests/infos/SmartCasts.kt | 10 ++++----- .../diagnostics/tests/inline/isCheck.kt | 4 ++-- .../testData/diagnostics/tests/inline/when.kt | 2 +- .../tests/sealed/ExhaustiveOnRoot.kt | 4 ++-- .../sealed/NonExhaustiveWhenWithAnyCase.kt | 2 +- .../diagnostics/tests/smartCasts/kt10232.kt | 2 +- .../testData/diagnostics/tests/when/When.kt | 5 +++-- .../dynamicTypes/dynamicCastTarget.kt | 20 +++++++++--------- .../testsWithStdLib/cast/IsArray.kt | 2 +- idea/testData/checker/IsExpressions.kt | 2 +- idea/testData/checker/When.kt | 4 ++-- idea/testData/checker/infos/SmartCasts.kt | 10 ++++----- 36 files changed, 123 insertions(+), 76 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b41ab2ff7ea..6392ded875d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -826,6 +826,8 @@ public interface Errors { DiagnosticFactory0 ALWAYS_NULL = DiagnosticFactory0.create(WARNING); DiagnosticFactory0 USELESS_NULLABLE_CHECK = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE); + DiagnosticFactory1 USELESS_IS_CHECK = DiagnosticFactory1.create(WARNING); + // Properties / locals diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index e6bb6b7ed85..9ba12409967 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -396,6 +396,7 @@ public class DefaultErrorMessages { MAP.put(IS_ENUM_ENTRY, "'is' over enum entry is not allowed, use comparison instead"); MAP.put(ENUM_ENTRY_AS_TYPE, "Use of enum entry names as types is not allowed, use enum type instead"); MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type"); + MAP.put(USELESS_IS_CHECK, "Check for instance is always ''{0}''", TO_STRING); MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE); MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE); MAP.put(WRONG_SETTER_RETURN_TYPE, "Setter return type must be Unit"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt index a5d0412094d..7df1b2f7f9e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt @@ -39,6 +39,8 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.* import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo +import org.jetbrains.kotlin.types.typeUtil.containsError +import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import java.util.* class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTypingInternals) : ExpressionTypingVisitor(facade) { @@ -51,7 +53,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping val typeReference = expression.typeReference if (typeReference != null && knownType != null) { val dataFlowValue = DataFlowValueFactory.createDataFlowValue(leftHandSide, knownType, context) - val conditionInfo = checkTypeForIs(context, knownType, typeReference, dataFlowValue).thenInfo + val conditionInfo = checkTypeForIs(context, expression, expression.isNegated, knownType, typeReference, dataFlowValue).thenInfo val newDataFlowInfo = conditionInfo.and(typeInfo.dataFlowInfo) context.trace.record(BindingContext.DATAFLOW_INFO_AFTER_CONDITION, expression, newDataFlowInfo) } @@ -342,7 +344,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping } val typeReference = condition.typeReference if (typeReference != null) { - val result = checkTypeForIs(context, subjectType, typeReference, subjectDataFlowValue) + val result = checkTypeForIs(context, condition, condition.isNegated, subjectType, typeReference, subjectDataFlowValue) if (condition.isNegated) { newDataFlowInfo = ConditionalDataFlowInfo(result.elseInfo, result.thenInfo) } @@ -417,6 +419,8 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping private fun checkTypeForIs( context: ExpressionTypingContext, + isCheck: KtElement, + negated: Boolean, subjectType: KotlinType, typeReferenceAfterIs: KtTypeReference, subjectDataFlowValue: DataFlowValue @@ -432,13 +436,21 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping if (targetDescriptor != null && DescriptorUtils.isEnumEntry(targetDescriptor)) { context.trace.report(IS_ENUM_ENTRY.on(typeReferenceAfterIs)) } - - if (!TypeUtils.isNullableType(subjectType) && targetType.isMarkedNullable) { + val subjectTypeHasError = subjectType.containsError() + if (!subjectTypeHasError && !TypeUtils.isNullableType(subjectType) && targetType.isMarkedNullable) { val element = typeReferenceAfterIs.typeElement assert(element is KtNullableType) { "element must be instance of " + KtNullableType::class.java.name } context.trace.report(Errors.USELESS_NULLABLE_CHECK.on(element as KtNullableType)) } checkTypeCompatibility(context, targetType, subjectType, typeReferenceAfterIs) + if (!subjectTypeHasError && !targetType.containsError()) { + val possibleTypes = hashSetOf(subjectType) + possibleTypes.addAll(context.dataFlowInfo.getStableTypes(subjectDataFlowValue)) + val intersection = TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, possibleTypes.map { it.upperIfFlexible() }) + if (intersection?.isSubtypeOf(targetType) ?: false) { + context.trace.report(Errors.USELESS_IS_CHECK.on(isCheck, !negated)) + } + } if (CastDiagnosticsUtil.isCastErased(subjectType, targetType, KotlinTypeChecker.DEFAULT)) { context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(typeReferenceAfterIs, targetType)) } diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt index f81d3a2969f..7e23bcbd9c4 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt @@ -18,11 +18,11 @@ class MyColor(val x: Color.RED, y: Color.RED): Color.RED = arg val temp: Color.RED = Color.RED temp as? Color.RED - if (temp is Color.RED) { + if (temp is Color.RED) { return temp as Color.RED } val obj = object : Color.RED {} - if (obj is Color.RED) { + if (obj is Color.RED) { return obj } return Color.RED diff --git a/compiler/testData/diagnostics/tests/IsExpressions.kt b/compiler/testData/diagnostics/tests/IsExpressions.kt index 141687c2286..fe3dc6b8cbe 100644 --- a/compiler/testData/diagnostics/tests/IsExpressions.kt +++ b/compiler/testData/diagnostics/tests/IsExpressions.kt @@ -1,7 +1,26 @@ +// FILE: KotlinFile.kt + fun test() { - if (1 is Int) { + if (1 is Int) { if (1 is Boolean) { } } + + A.create() is A + A.create() is A? + + unresolved is A + unresolved is A? + + val x = foo() + x as String + x is String } + +fun foo(): Any = "" + +// FILE: A.java +class A { + static A create() { return null; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/IsExpressions.txt b/compiler/testData/diagnostics/tests/IsExpressions.txt index 93e27f34c8c..b7b146b602b 100644 --- a/compiler/testData/diagnostics/tests/IsExpressions.txt +++ b/compiler/testData/diagnostics/tests/IsExpressions.txt @@ -1,3 +1,14 @@ package +public fun foo(): kotlin.Any public fun test(): kotlin.Unit + +public/*package*/ open class A { + public/*package*/ constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public/*package*/ open fun create(): A! +} diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.kt b/compiler/testData/diagnostics/tests/LValueAssignment.kt index 1f44d0860ed..20f4baeea06 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.kt @@ -46,7 +46,7 @@ fun cannotBe() { foo() = Unit; (i as Int) = 34 - (i is Int) = false + (i is Int) = false A() = A() 5 = 34 } diff --git a/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.kt b/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.kt index f927fd0cee0..d4b38cb4974 100644 --- a/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.kt +++ b/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.kt @@ -45,10 +45,10 @@ fun test(a: Any) { .0fin a .0din a - 1is Any + 1is Any 1as Any 1as? Any - 1!is Any + 1!is Any 1!in a } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.kt b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.kt index e60d4b6170c..446a02b22d2 100644 --- a/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.kt +++ b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.kt @@ -31,7 +31,8 @@ fun test(a: Any) { a !in's' a !in'' - if("s"is Any) {} + if("s"is Any) {} + if("s"is Any) {} test("s"as Any) a foo""1 diff --git a/compiler/testData/diagnostics/tests/annotations/ConstructorCall.kt b/compiler/testData/diagnostics/tests/annotations/ConstructorCall.kt index 1d9819d4b07..f6f673b2631 100644 --- a/compiler/testData/diagnostics/tests/annotations/ConstructorCall.kt +++ b/compiler/testData/diagnostics/tests/annotations/ConstructorCall.kt @@ -26,7 +26,7 @@ fun foo() { } fun bar(a: Ann = Ann()) { - if (a is Ann) {} + if (a is Ann) {} } operator fun String.invoke() {} diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.kt index 51c6eab4642..f4e4c9a8453 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.kt @@ -2,4 +2,4 @@ open class Base class Some: Base() // a is Some => a is Base -fun f(a: Some) = a is Base \ No newline at end of file +fun f(a: Some) = a is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.kt index db875931272..eafc428eeb5 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.kt @@ -5,4 +5,4 @@ open class Base class SubBase: Base() // f is SubBase => f is Base => (Base, B <: A) f is Base -fun test(f: SubBase) = f is Base \ No newline at end of file +fun test(f: SubBase) = f is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.kt index a7ca5876259..aa50f251377 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.kt @@ -5,4 +5,4 @@ open class Base class SubBase: Base() // f is SubBase => (SubBase <: Base) f is Base => (B <: A, Base => SubBase <: Base) f is Base -fun test(f: SubBase) = f is Base \ No newline at end of file +fun test(f: SubBase) = f is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt index 29ac268ad0f..7000a879e06 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt @@ -1 +1 @@ -fun f(a: MutableList) = a is MutableList +fun f(a: MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.kt index 6f7bc4f981a..1ad94336466 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.kt @@ -1 +1 @@ -fun f(a: MutableList) = a is MutableList +fun f(a: MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt index f1ba3800c08..3b47296763c 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt @@ -1 +1 @@ -fun f(a: List) = a is List +fun f(a: List) = a is List diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedTasT.kt b/compiler/testData/diagnostics/tests/cast/IsErasedTasT.kt index ae1fa33c9f8..03c602a643d 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedTasT.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedTasT.kt @@ -1 +1 @@ -fun testing(a: T) = a is T +fun testing(a: T) = a is T diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt index 78814190537..d566bac0d57 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt @@ -1,14 +1,14 @@ fun test(x: T?, y: S, z: T) { x is T - x is T? + x is T? - y is T - y is S - y is T? - y is S? + y is T + y is S + y is T? + y is S? - z is T - z is T? + z is T + z is T? null as T null as T? @@ -22,6 +22,6 @@ inline fun test(x: T?) { } fun foo(x: List, y: List?) { - x is List + x is List y is List } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.kt b/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.kt index 77abb9301c3..5dd66687fbf 100644 --- a/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.kt +++ b/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.kt @@ -22,17 +22,17 @@ public class JavaClass { // FILE: test.kt fun test(x1: T, x2: T?, y1: S, y2: S?) { - x1 is T? - x2 is T? - y1 is S? - y2 is S? + x1 is T? + x2 is T? + y1 is S? + y2 is S? val f1 = JavaClass.foo() - f1 is Int? + f1 is Int? val f2 = JavaClass.fooN() - f2 is Int? + f2 is Int? val f3 = JavaClass.fooNN() - f3 is Int? + f3 is Int? } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt index 979ac9e3272..996e2b017c6 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt @@ -38,7 +38,7 @@ fun t1(b : Boolean) { return; } doSmth(i) - if (i is Int) { + if (i is Int) { return; } } diff --git a/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt b/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt index 9b72afbba66..3df703a08dd 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt @@ -26,7 +26,7 @@ fun t1(x: Int) = when(x) { } fun t5(x: Int) = when (x) { - is Int -> 1 + is Int -> 1 2 -> 2 } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.kt index e011bce3a25..ae1365a9934 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.kt @@ -1,7 +1,7 @@ // !CHECK_TYPE fun foo(x: Number) { - if ((x as Int) is Int) { + if ((x as Int) is Int) { checkSubtype(x) } checkSubtype(x) diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.kt index 495fc431acc..7d45bc9e2e1 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.kt @@ -1,11 +1,11 @@ // !CHECK_TYPE fun noUselessDataFlowInfoCreation(x: Number) { - if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { - if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { - if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { - if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { - if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { } } } } } } } } } } } } } } } } } } } } } } } } } } diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.kt index 6659a53794c..748e1b72a9b 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.kt @@ -7,7 +7,7 @@ class DerivedOuter : SuperOuter() { } fun bare(x: SuperOuter<*>.SuperInner<*>, y: Any?) { - if (x is SuperOuter.SuperInner) return + if (x is SuperOuter.SuperInner) return if (y is SuperOuter.SuperInner) { return } diff --git a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt index 3c036401686..a0a6ff39863 100644 --- a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt +++ b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt @@ -35,7 +35,7 @@ fun f10(init : A?) { if (!(a is B)) { return; } - if (!(a is B)) { + if (!(a is B)) { return; } } @@ -57,7 +57,7 @@ fun f11(a : A?) { is B -> a.bar() is A -> a.foo() is Any -> a.foo() - is Any? -> a.bar() + is Any? -> a.bar() else -> a?.foo() } } @@ -67,12 +67,12 @@ fun f12(a : A?) { is B -> a.bar() is A -> a.foo() is Any -> a.foo(); - is Any? -> a.bar() + is Any? -> a.bar() is C -> a.bar() else -> a?.foo() } - if (a is Any?) { + if (a is Any?) { a?.bar() } if (a is B) { @@ -197,7 +197,7 @@ fun mergeSmartCasts(a: Any?) { when (a) { is String, is Any -> a.compareTo("") } - if (a is String && a is Any) { + if (a is String && a is Any) { val i: Int = a.compareTo("") } if (a is String && a.compareTo("") == 0) {} diff --git a/compiler/testData/diagnostics/tests/inline/isCheck.kt b/compiler/testData/diagnostics/tests/inline/isCheck.kt index 9aab3d5c8bf..8eb5d081810 100644 --- a/compiler/testData/diagnostics/tests/inline/isCheck.kt +++ b/compiler/testData/diagnostics/tests/inline/isCheck.kt @@ -5,6 +5,6 @@ inline public fun reg(converter: (Any) -> Any, flag: Boolean) { } public inline fun register(converter: (Any) -> Any) { - converter is (Any) -> Any - reg(converter, converter is (Any) -> Any) + converter is (Any) -> Any + reg(converter, converter is (Any) -> Any) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/when.kt b/compiler/testData/diagnostics/tests/inline/when.kt index 43853c94bc0..26914fe0018 100644 --- a/compiler/testData/diagnostics/tests/inline/when.kt +++ b/compiler/testData/diagnostics/tests/inline/when.kt @@ -5,7 +5,7 @@ inline public fun reg(converter: (Any) -> Any) { public inline fun register(converter: (Any) -> Any) { reg(when(converter) { - is (Any) -> Any -> converter + is (Any) -> Any -> converter else -> converter }) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.kt index cdb5b081b38..a6e5d26fe91 100644 --- a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.kt +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.kt @@ -9,7 +9,7 @@ sealed class Expr : Stmt() { fun test(x: Stmt): String = when (x) { is Expr -> "expr" - is Stmt -> "stmt" + is Stmt -> "stmt" } fun test2(x: Stmt): String = @@ -19,5 +19,5 @@ fun test2(x: Stmt): String = fun test3(x: Expr): String = when (x) { - is Stmt -> "stmt" + is Stmt -> "stmt" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.kt b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.kt index fc235670129..f6cf690492c 100644 --- a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.kt +++ b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.kt @@ -9,7 +9,7 @@ sealed class Sealed { fun foo(s: Sealed): Int { return when(s) { is Sealed.First -> 1 - !is Any -> 0 + !is Any -> 0 } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt index 00840f11164..502d68c577b 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt @@ -6,7 +6,7 @@ interface B : A fun foo(b: A) = b fun test(a: A) { - if (a is Any) { + if (a is Any) { // Error:(9, 9) Kotlin: Type inference failed: fun foo(b: A): kotlin.Unit // cannot be applied to (A) foo(a) diff --git a/compiler/testData/diagnostics/tests/when/When.kt b/compiler/testData/diagnostics/tests/when/When.kt index e4b246c6854..f05e2b0c6b8 100644 --- a/compiler/testData/diagnostics/tests/when/When.kt +++ b/compiler/testData/diagnostics/tests/when/When.kt @@ -5,8 +5,9 @@ fun foo() : Int { val x = 1 when (x) { is String -> 1 - !is Int -> 1 - is Any? -> 1 + !is Int -> 1 + is Any? -> 1 + is Any -> 1 s -> 1 1 -> 1 1 + a -> 1 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.kt index 13530d6ab61..f568074361a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.kt @@ -7,23 +7,23 @@ fun test(d: Any, dl: Collection) { d as? dynamic d as? dynamic? - d is dynamic - d is dynamic? + d is dynamic + d is dynamic? - d !is dynamic - d !is dynamic? + d !is dynamic + d !is dynamic? when (d) { - is dynamic -> {} - is dynamic? -> {} - !is dynamic -> {} - !is dynamic? -> {} + is dynamic -> {} + is dynamic? -> {} + !is dynamic -> {} + !is dynamic? -> {} } dl as List - dl is List + dl is List when (dl) { - is List -> {} + is List -> {} } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.kt b/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.kt index 42ed82698b3..2e41788a05b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.kt @@ -1,5 +1,5 @@ fun f(a: Array) = a.isArrayOf() -fun f1(a: Array) = a is Array<*> +fun f1(a: Array) = a is Array<*> fun f2(a: Array) = a is Array \ No newline at end of file diff --git a/idea/testData/checker/IsExpressions.kt b/idea/testData/checker/IsExpressions.kt index 877556791a1..e598db9d31c 100644 --- a/idea/testData/checker/IsExpressions.kt +++ b/idea/testData/checker/IsExpressions.kt @@ -1,5 +1,5 @@ fun test() { - if (1 is Int) { + if (1 is Int) { if (1 is Boolean) { } diff --git a/idea/testData/checker/When.kt b/idea/testData/checker/When.kt index fade41566c0..739eb185e58 100644 --- a/idea/testData/checker/When.kt +++ b/idea/testData/checker/When.kt @@ -5,8 +5,8 @@ fun foo() : Int { val x = 1 when (x) { is String -> 1 - !is Int -> 1 - is Any? -> 1 + !is Int -> 1 + is Any? -> 1 s -> 1 1 -> 1 1 + a -> 1 diff --git a/idea/testData/checker/infos/SmartCasts.kt b/idea/testData/checker/infos/SmartCasts.kt index 70f634e5a84..51cfc85dbd1 100644 --- a/idea/testData/checker/infos/SmartCasts.kt +++ b/idea/testData/checker/infos/SmartCasts.kt @@ -49,7 +49,7 @@ fun f10(a : A?) { if (!(a is B)) { return; } - if (!(a is B)) { + if (!(a is B)) { return; } } @@ -71,7 +71,7 @@ fun f11(a : A?) { is B -> a.bar() is A -> a.foo() is Any -> a.foo() - is Any? -> a.bar() + is Any? -> a.bar() else -> a?.foo() } } @@ -81,12 +81,12 @@ fun f12(a : A?) { is B -> a.bar() is A -> a.foo() is Any -> a.foo(); - is Any? -> a.bar() + is Any? -> a.bar() is C -> a.bar() else -> a?.foo() } - if (a is Any?) { + if (a is Any?) { a?.bar() } if (a is B) { @@ -203,7 +203,7 @@ fun mergeSmartCasts(a: Any?) { when (a) { is String, is Any -> a.compareTo("") } - if (a is String && a is Any) { + if (a is String && a is Any) { val i: Int = a.compareTo("") } if (a is String && a.compareTo("") == 0) {}