From ae3497c6ce95cc6ebc8b466c34e0d0b01dfb584b Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 28 Jul 2017 16:41:21 +0300 Subject: [PATCH] Reduce highlighting range for UNCHECKED_CAST #KT-18985 Fixed --- .../src/org/jetbrains/kotlin/diagnostics/Errors.java | 2 +- .../testData/diagnostics/tests/EnumEntryAsType.kt | 2 +- compiler/testData/diagnostics/tests/cast/AsArray.kt | 2 +- .../testData/diagnostics/tests/cast/AsErasedError.kt | 2 +- .../diagnostics/tests/cast/AsErasedWarning.kt | 2 +- .../diagnostics/tests/cast/AsWithOtherParameter.kt | 12 ++++++------ .../tests/cast/IsErasedUpcastToNonReified.kt | 4 ++-- .../inference/differentDelegatedExpressions.kt | 2 +- .../generics/capturedParameters/uncheckedCast.kt | 6 +++--- .../tests/inference/upperBounds/kt2856.kt | 2 +- .../diagnostics/tests/library/Collections.kt | 4 ++-- .../diagnostics/tests/nullableTypes/uselessElvis.kt | 4 ++-- .../platformTypes/genericVarianceViolation/simple.kt | 10 +++++----- .../genericVarianceViolation/smartCast.kt | 2 +- .../testData/diagnostics/tests/regressions/kt307.kt | 6 +++--- .../testData/diagnostics/tests/regressions/kt498.kt | 2 +- .../testData/diagnostics/tests/regressions/kt716.kt | 2 +- .../testData/diagnostics/tests/smartCasts/kt10444.kt | 4 ++-- .../testData/diagnostics/tests/smartCasts/kt3224.kt | 2 +- .../diagnostics/tests/substitutions/kt4887.kt | 2 +- .../suppress/oneWarning/onBlockStatementSameLine.kt | 8 ++++---- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 1e8444be145..d662e803103 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -830,7 +830,7 @@ public interface Errors { // Casts and is-checks DiagnosticFactory1 CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR); - DiagnosticFactory2 UNCHECKED_CAST = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 UNCHECKED_CAST = DiagnosticFactory2.create(WARNING, AS_TYPE); DiagnosticFactory0 USELESS_CAST = DiagnosticFactory0.create(WARNING, AS_TYPE); DiagnosticFactory0 CAST_NEVER_SUCCEEDS = DiagnosticFactory0.create(WARNING); diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt index 7e23bcbd9c4..eafd23d7bc7 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt @@ -43,7 +43,7 @@ typealias ArrayOfEnumEntry = ArrayRED> typealias ArrayOfEnumEntryAlias = Array -fun bar(a: Any): T = a as T +fun bar(a: Any): T = a as T fun foo() { fooRED>() diff --git a/compiler/testData/diagnostics/tests/cast/AsArray.kt b/compiler/testData/diagnostics/tests/cast/AsArray.kt index d4b86b61325..8cf8539a071 100644 --- a/compiler/testData/diagnostics/tests/cast/AsArray.kt +++ b/compiler/testData/diagnostics/tests/cast/AsArray.kt @@ -1 +1 @@ -fun f(x: Any) = x as Array \ No newline at end of file +fun f(x: Any) = x as Array \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedError.kt b/compiler/testData/diagnostics/tests/cast/AsErasedError.kt index a9c644c04aa..c262c2e91a1 100644 --- a/compiler/testData/diagnostics/tests/cast/AsErasedError.kt +++ b/compiler/testData/diagnostics/tests/cast/AsErasedError.kt @@ -1,2 +1,2 @@ -fun ff(c: MutableCollection) = c as MutableList +fun ff(c: MutableCollection) = c as MutableList diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedWarning.kt b/compiler/testData/diagnostics/tests/cast/AsErasedWarning.kt index c513e0e7a30..89112802eb4 100644 --- a/compiler/testData/diagnostics/tests/cast/AsErasedWarning.kt +++ b/compiler/testData/diagnostics/tests/cast/AsErasedWarning.kt @@ -1,2 +1,2 @@ -fun ff(a: Any) = a as MutableList +fun ff(a: Any) = a as MutableList diff --git a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt index 46743735ec5..4803ddb150a 100644 --- a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt +++ b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.kt @@ -3,7 +3,7 @@ class Class(val name: String, val instance: T) fun test(clazz: Class) { - println((clazz as Class).name) + println((clazz as Class).name) } fun use() { @@ -12,22 +12,22 @@ fun use() { fun checkArrays(): Array { val someArray = arrayOfNulls(5) - someArray as Array - return someArray as Array + someArray as Array + return someArray as Array } class Wrapper(val x: T) fun checkArrays2(): Array> { val someArray = arrayOf(Wrapper(1), Wrapper(2)) - return someArray as Array> + return someArray as Array> } fun checkArrays3() { val someArray = arrayOfNulls(1) - someArray as Array + someArray as Array val intArray = arrayOfNulls(1) - intArray as Array + intArray as Array } fun println(s: String) = s diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt index d566bac0d57..9ab75201fcd 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.kt @@ -10,9 +10,9 @@ fun test(x: T?, y: S, z: T) { z is T z is T? - null as T + null as T null as T? - null as S + null as S } inline fun test(x: T?) { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt index 84a17d38cec..816fa153b03 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt @@ -25,7 +25,7 @@ class MyProperty { operator fun getValue(thisRef: R, desc: KProperty<*>): T { println("get $thisRef ${desc.name}") - return null as T + return null as T } operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) { diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.kt index dea38f0a6b3..ecdcb99eb61 100644 --- a/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.kt +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.kt @@ -6,11 +6,11 @@ fun foo(x: Any, y: Any) : Any { } if (1 == 2) { - x as C + x as C } if (2 == 3) { - x as? C + x as? C } class Outer { @@ -22,7 +22,7 @@ fun foo(x: Any, y: Any) : Any { return y } - y as Outer<*>.Inner + y as Outer<*>.Inner return C() } diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt index 1ddb0d17fb9..24da80ea969 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt @@ -5,7 +5,7 @@ import java.util.HashMap public inline fun Map.getOrElse1(key: K, defaultValue: ()-> V1) : V1 { if (this.containsKey(key)) { - return this.get(key) as V + return this.get(key) as V } else { return defaultValue() } diff --git a/compiler/testData/diagnostics/tests/library/Collections.kt b/compiler/testData/diagnostics/tests/library/Collections.kt index bd34b129b1b..f3835f6a292 100644 --- a/compiler/testData/diagnostics/tests/library/Collections.kt +++ b/compiler/testData/diagnostics/tests/library/Collections.kt @@ -26,7 +26,7 @@ fun testMutableCollection(c: MutableCollection, t: T) { val mutableIterator: MutableIterator = c.iterator() c.add(t) - c.remove(1 as T) + c.remove(1 as T) c.addAll(c) c.removeAll(c) c.retainAll(c) @@ -84,7 +84,7 @@ fun testMutableSet(s: MutableSet, t: T) { val mutableIterator: MutableIterator = s.iterator() s.add(t) - s.remove(1 as T) + s.remove(1 as T) s.addAll(s) s.removeAll(s) s.retainAll(s) diff --git a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt index 6f7468ea97c..9c8f350401c 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt @@ -1,11 +1,11 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST fun test1(t: Any?): Any { - return t as T ?: "" + return t as T ?: "" } fun test2(t: Any?): Any { - return t as T ?: "" + return t as T ?: "" } fun test3(t: Any?): Any { diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.kt index 5c754741f59..303e271f312 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.kt @@ -27,7 +27,7 @@ fun main( // Lists a.foo(ml) a.foo(l) - a.foo(ml as MutableList) + a.foo(ml as MutableList) a.foo(l as List) // Iterables @@ -43,25 +43,25 @@ fun main( // Sets a.foo(ms) a.foo(s) - a.foo(ms as MutableSet) + a.foo(ms as MutableSet) a.foo(s as Set) // Maps a.foo(mm) a.foo(m) - a.foo(mm as MutableMap) + a.foo(mm as MutableMap) a.foo(m as Map) // Map entries a.foo(mme) a.foo(me) - a.foo(mme as MutableMap.MutableEntry) + a.foo(mme as MutableMap.MutableEntry) a.foo(me as Map.Entry) // Lists of lists a.foo(mll) a.foo(ll) - a.foo(mll as MutableList>) + a.foo(mll as MutableList>) a.foo(ll as List>) } diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.kt index 5f88836bdab..7a7e03f21a2 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.kt @@ -11,6 +11,6 @@ public class A { fun main(a: A, ml: Any) { if (ml is MutableList) { a.foo(ml) - a.foo(ml as List) + a.foo(ml as List) } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt307.kt b/compiler/testData/diagnostics/tests/regressions/kt307.kt index 5b79f91fe5f..ebc11869511 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt307.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt307.kt @@ -5,7 +5,7 @@ open class AL { } interface ALE : AL { -fun getOrNull(index: Int, value: T) : T { -return get(index) as? T ?: value -} + fun getOrNull(index: Int, value: T) : T { + return get(index) as? T ?: value + } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt498.kt b/compiler/testData/diagnostics/tests/regressions/kt498.kt index 5af9b46576d..d6eac9c2129 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt498.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt498.kt @@ -3,5 +3,5 @@ class IdUnavailableException() : Exception() {} fun T.getJavaClass() : Class { - return ((this as Object).getClass()) as Class // Some error here, because of Exception() used above. ?!!! + return ((this as Object).getClass()) as Class // Some error here, because of Exception() used above. ?!!! } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt716.kt b/compiler/testData/diagnostics/tests/regressions/kt716.kt index b1582f70182..f4a244447c2 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt716.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt716.kt @@ -6,7 +6,7 @@ fun typeinfo() : TypeInfo = null as TypeInfo fun TypeInfo.getJavaClass() : java.lang.Class { val t : java.lang.Object = this as java.lang.Object - return t.getClass() as java.lang.Class // inferred type is Object but Serializable was expected + return t.getClass() as java.lang.Class // inferred type is Object but Serializable was expected } fun getJavaClass() = typeinfo().getJavaClass() diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt index 4a7dcb0e5b4..5838a0b26af 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt @@ -3,12 +3,12 @@ class Qwe(val a: T?) { fun test1(obj: Any) { - obj as Qwe + obj as Qwe check(obj.a) } fun test1(obj: Qwe<*>) { - obj as Qwe + obj as Qwe check(obj.a) } diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3224.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3224.kt index ce8393eec86..4d563a84c1d 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/kt3224.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3224.kt @@ -1,7 +1,7 @@ // Works already in M11 fun test(c : Class<*>) { - val sc = c as Class + val sc = c as Class // No ambiguous overload c.getAnnotations(); sc.getAnnotations(); diff --git a/compiler/testData/diagnostics/tests/substitutions/kt4887.kt b/compiler/testData/diagnostics/tests/substitutions/kt4887.kt index 8f369710ee8..016eed78e41 100644 --- a/compiler/testData/diagnostics/tests/substitutions/kt4887.kt +++ b/compiler/testData/diagnostics/tests/substitutions/kt4887.kt @@ -3,6 +3,6 @@ package h public class MyClass(param: MyClass) { fun test() { val result: MyClass? = null - MyClass(result as MyClass) + MyClass(result as MyClass) } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt index 6234a1ce219..6cc72a4bb0d 100644 --- a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt @@ -1,7 +1,7 @@ fun foo(x: Array, block: (T, Int) -> Int) { var r: Any? - @Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int) + @Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int) // to prevent unused assignment diagnostic for the above statement r.hashCode() @@ -9,11 +9,11 @@ fun foo(x: Array, block: (T, Int) -> Int) { var i = 1 if (i != 1) { - @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() + @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() } if (i != 1) @Suppress("UNCHECKED_CAST") - i += block(x[0] as T, "" as Int).toInt() + i += block(x[0] as T, "" as Int).toInt() - if (i != 1) @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() + if (i != 1) @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() }