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
This commit is contained in:
+11
-2
@@ -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
|
||||
)
|
||||
|
||||
+1
@@ -2,5 +2,6 @@ import kotlin.reflect.*
|
||||
|
||||
fun foo() {
|
||||
String::class.primaryConstructor
|
||||
::foo.isExternal
|
||||
listOf(42)
|
||||
}
|
||||
|
||||
+7
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user