From 859bccb9fcb36112348a693d2ac76c133e9f8791 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 21 Mar 2017 01:28:59 +0300 Subject: [PATCH] Propagate resolution results without ambiguity to constant evaluator This allows to get rid of useless diagnostics that some value is not a constant --- .../expressions/BasicExpressionTypingVisitor.java | 10 +++++----- .../tests/collectionLiterals/argumentsOfAnnotation.txt | 2 +- .../argumentsOfAnnotationWithKClass.txt | 4 ++-- .../collectionLiterals/defaultValuesInAnnotation.kt | 10 +++++----- .../defaultValuesWithConstantsInAnnotation.kt | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 7ed438cd875..d105f3dac51 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -1804,15 +1804,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } Call call = CallMaker.makeCallForCollectionLiteral(collectionLiteralExpression); - OverloadResolutionResults functionResults = components.callResolver.resolveCallWithGivenName( + OverloadResolutionResults resolutionResults = components.callResolver.resolveCallWithGivenName( context, call, collectionLiteralExpression, collectionLiteralCallName); - if (!functionResults.isSuccess() || !functionResults.isSingleResult()) { - // TODO: report an error + // TODO: check that resolved function is from package `kotlin`, otherwise report an error + if (!resolutionResults.isSingleResult()) { return TypeInfoFactoryKt.noTypeInfo(context); } - context.trace.record(COLLECTION_LITERAL_CALL, collectionLiteralExpression, functionResults.getResultingCall()); - return TypeInfoFactoryKt.createTypeInfo(functionResults.getResultingDescriptor().getReturnType(), context); + context.trace.record(COLLECTION_LITERAL_CALL, collectionLiteralExpression, resolutionResults.getResultingCall()); + return TypeInfoFactoryKt.createTypeInfo(resolutionResults.getResultingDescriptor().getReturnType(), context); } } diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.txt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.txt index 8046ad6784f..1088834eb80 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.txt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.txt @@ -4,7 +4,7 @@ public const val ONE: kotlin.Int = 1 public val two: kotlin.Int = 2 @Foo(a = {1}, b = {"/"}, c = {1.0.toFloat()}) public fun test1(): kotlin.Unit @Foo(a = {}, b = {}, c = {}) public fun test2(): kotlin.Unit -@Foo public fun test3(): kotlin.Unit +@Foo(a = {1.0.toFloat()}, b = {\u0020 (' ')}, c = {1}) public fun test3(): kotlin.Unit @Foo(a = {1}, b = {""}, c = {1.0.toFloat()}) public fun test4(): kotlin.Unit @Foo(a = {3}, b = {"Hello, Kotlin"}, c = {Infinity.toFloat()}) public fun test5(): kotlin.Unit @Foo(a = {1}, b = {}, c = {}) public fun test6(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.txt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.txt index 8194a59e9b2..3f3152bab3b 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.txt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.txt @@ -4,8 +4,8 @@ package @Foo(a = {kotlin.Int::class, kotlin.String::class}) public fun test2(): kotlin.Unit @Foo(a = {kotlin.Array<*>::class}) public fun test3(): kotlin.Unit @Foo(a = {Gen::class}) public fun test4(): kotlin.Unit -@Foo public fun test5(): kotlin.Unit -@Foo public fun test6(): kotlin.Unit +@Foo(a = {""}) public fun test5(): kotlin.Unit +@Foo(a = {kotlin.Int::class, 1}) public fun test6(): kotlin.Unit @Bar public fun test7(): kotlin.Unit public final annotation class Bar : kotlin.Annotation { diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt index 902039fb0e9..b951527d02f 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt @@ -5,9 +5,9 @@ annotation class Foo( ) annotation class Bar( - val a: Array = [' '], - val b: Array = ["", ''], - val c: Array = [1] + val a: Array = [' '], + val b: Array = ["", ''], + val c: Array = [1] ) annotation class Base( @@ -18,6 +18,6 @@ annotation class Base( ) annotation class Err( - val a: IntArray = [1L], - val b: Array = [1] + val a: IntArray = [1L], + val b: Array = [1] ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.kt index 1f716f54b09..ba318edbc55 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.kt @@ -17,7 +17,7 @@ annotation class Bar( ) annotation class Baz( - val a: IntArray = [null], - val b: IntArray = [1, null, 2], + val a: IntArray = [null], + val b: IntArray = [1, null, 2], val c: IntArray = [this] )