Don't silently ignore argument mismatch for provide delegate

#KT-39816 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-06-26 11:04:43 +03:00
parent ea5fef76d1
commit a87b25d10e
9 changed files with 92 additions and 2 deletions
@@ -6186,6 +6186,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt");
}
@TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt")
public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt");
}
@TestMetadata("provideDelegateOperatorDeclaration.kt")
public void testProvideDelegateOperatorDeclaration() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");
@@ -571,7 +571,7 @@ class DelegatedPropertyResolver(
variableDescriptor, delegateExpression, delegateTypeWithoutNonFixedVariables, contextForProvideDelegate
)
if (conventionMethodFound(provideDelegateResults)) {
if (provideDelegateResults.isSuccess) {
val provideDelegateDescriptor = provideDelegateResults.resultingDescriptor
if (provideDelegateDescriptor.isOperator) {
delegateType = inverseSubstitution(provideDelegateDescriptor.returnType, substitutionMap) ?: return null
@@ -0,0 +1,2 @@
Failures detected in FirBodyResolveTransformerAdapter, file: /provideDelegateOnFunctionalTypeWithThis.fir.kt
Cause: java.lang.ClassCastException: org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl cannot be cast to org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
@@ -0,0 +1,22 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_RUNTIME
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class CaptureContext<A>(val capture: (A) -> Unit) : ReadOnlyProperty<A, () -> Unit> {
override fun getValue(thisRef: A, property: KProperty<*>) = { -> capture(thisRef) }
}
operator fun <A> ((A) -> Unit).provideDelegate(thisRef: A, property: KProperty<*>) = CaptureContext(this)
fun wrong(arg: Wrong) {}
class Wrong
class Right {
val prop: () -> Unit by <!DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>::wrong<!>
}
fun box(): String {
Right().prop()
return "OK"
}
@@ -0,0 +1,22 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_RUNTIME
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class CaptureContext<A>(val capture: (A) -> Unit) : ReadOnlyProperty<A, () -> Unit> {
override fun getValue(thisRef: A, property: KProperty<*>) = { -> capture(thisRef) }
}
operator fun <A> ((A) -> Unit).provideDelegate(thisRef: A, property: KProperty<*>) = CaptureContext(this)
fun wrong(arg: Wrong) {}
class Wrong
class Right {
val prop: () -> Unit by <!DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>::wrong<!>
}
fun box(): String {
Right().prop()
return "OK"
}
@@ -0,0 +1,29 @@
package
public fun box(): kotlin.String
public fun wrong(/*0*/ arg: Wrong): kotlin.Unit
public operator fun </*0*/ A> ((A) -> kotlin.Unit).provideDelegate(/*0*/ thisRef: A, /*1*/ property: kotlin.reflect.KProperty<*>): CaptureContext<A>
public final class CaptureContext</*0*/ A> : kotlin.properties.ReadOnlyProperty<A, () -> kotlin.Unit> {
public constructor CaptureContext</*0*/ A>(/*0*/ capture: (A) -> kotlin.Unit)
public final val capture: (A) -> kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun getValue(/*0*/ thisRef: A, /*1*/ property: kotlin.reflect.KProperty<*>): () -> kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Right {
public constructor Right()
public final val prop: () -> kotlin.Unit
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
}
public final class Wrong {
public constructor Wrong()
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
}
@@ -11,7 +11,7 @@ operator fun <T> String.provideDelegate(receiver: Any?, p: Any) = Delegate<T>()
var test1: String by <!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Delegate<!>()
var test2: String by Delegate<String>()
var test3: String by <!OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>"OK"<!>
var test3: String by <!NI;DELEGATE_SPECIAL_FUNCTION_MISSING, NI;DELEGATE_SPECIAL_FUNCTION_MISSING, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>"OK"<!>
var test4: String by "OK".<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>provideDelegate<!>(null, "")
var test5: String by "OK".provideDelegate<String>(null, "")
@@ -6193,6 +6193,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt");
}
@TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt")
public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt");
}
@TestMetadata("provideDelegateOperatorDeclaration.kt")
public void testProvideDelegateOperatorDeclaration() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");
@@ -6188,6 +6188,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt");
}
@TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt")
public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt");
}
@TestMetadata("provideDelegateOperatorDeclaration.kt")
public void testProvideDelegateOperatorDeclaration() throws Exception {
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");