From 8811165de8e2dbffc5422942d41704392ed34578 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 30 Jan 2017 13:24:17 +0300 Subject: [PATCH] Report error on callable reference or class literal with "-no-stdlib" Also workaround the NoSuchElementException that was happening because error type never has any type arguments #KT-14547 Fixed --- .../expressions/DoubleColonExpressionResolver.kt | 13 +++++++++++-- compiler/testData/cli/jvm/noStdlib.kt | 1 + compiler/testData/cli/jvm/noStdlib.out | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index 03e664bd722..51a51d94a9a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -99,6 +99,9 @@ class DoubleColonExpressionResolver( checkClassLiteral(c, expression, result) val variance = if (result is DoubleColonLHS.Expression && !result.isObject) Variance.OUT_VARIANCE else Variance.INVARIANT val kClassType = reflectionTypes.getKClassType(Annotations.EMPTY, type, variance) + if (kClassType.isError) { + c.trace.report(MISSING_DEPENDENCY_CLASS.on(expression.receiverExpression!!, KotlinBuiltIns.FQ_NAMES.kClass.toSafe())) + } val dataFlowInfo = (result as? DoubleColonLHS.Expression)?.dataFlowInfo ?: c.dataFlowInfo return dataFlowAnalyzer.checkType(createTypeInfo(kClassType, dataFlowInfo), expression, c) } @@ -509,6 +512,9 @@ class DoubleColonExpressionResolver( checkReferenceIsToAllowedMember(descriptor, context.trace, expression) val type = createKCallableTypeForReference(descriptor, lhs, reflectionTypes, context.scope.ownerDescriptor) ?: return null + if (type.isError) { + context.trace.report(MISSING_DEPENDENCY_CLASS.on(expression, KotlinBuiltIns.FQ_NAMES.kCallable.toSafe())) + } when (descriptor) { is FunctionDescriptor -> bindFunctionReference(expression, type, context) @@ -551,10 +557,13 @@ class DoubleColonExpressionResolver( /* isCoroutine = */ false ) + val parameterTypes = if (type.isError) emptyList() else type.arguments.dropLast(1) + val returnType = if (type.isError) null else type.arguments.last().type + functionDescriptor.initialize( null, null, emptyList(), - createValueParametersForInvokeInFunctionType(functionDescriptor, type.arguments.dropLast(1)), - type.arguments.last().type, + createValueParametersForInvokeInFunctionType(functionDescriptor, parameterTypes), + returnType, Modality.FINAL, Visibilities.PUBLIC ) diff --git a/compiler/testData/cli/jvm/noStdlib.kt b/compiler/testData/cli/jvm/noStdlib.kt index 9204affe880..73c9c89cddf 100644 --- a/compiler/testData/cli/jvm/noStdlib.kt +++ b/compiler/testData/cli/jvm/noStdlib.kt @@ -2,5 +2,6 @@ import kotlin.reflect.* fun foo() { String::class.primaryConstructor + ::foo.isExternal listOf(42) } diff --git a/compiler/testData/cli/jvm/noStdlib.out b/compiler/testData/cli/jvm/noStdlib.out index 087c3a949db..dc50f3644d1 100644 --- a/compiler/testData/cli/jvm/noStdlib.out +++ b/compiler/testData/cli/jvm/noStdlib.out @@ -1,7 +1,13 @@ compiler/testData/cli/jvm/noStdlib.kt:1:8: error: unresolved reference: kotlin import kotlin.reflect.* ^ -compiler/testData/cli/jvm/noStdlib.kt:5:5: error: unresolved reference: listOf +compiler/testData/cli/jvm/noStdlib.kt:4:5: error: cannot access class 'kotlin.reflect.KClass'. Check your module classpath for missing or conflicting dependencies + String::class.primaryConstructor + ^ +compiler/testData/cli/jvm/noStdlib.kt:5:5: error: cannot access class 'kotlin.reflect.KCallable'. Check your module classpath for missing or conflicting dependencies + ::foo.isExternal + ^ +compiler/testData/cli/jvm/noStdlib.kt:6:5: error: unresolved reference: listOf listOf(42) ^ COMPILATION_ERROR