Fix compiler failure related NO_EXPECTED_TYPE

Changes to turn KT-16016 into a compiler diagnostic error rather than a
stack trace

#KT-16016 Fixed
This commit is contained in:
Derek Alexander
2017-05-18 07:26:17 -04:00
committed by Stanislav Erokhin
parent ace3bfbbf9
commit 1f5cc059f9
4 changed files with 20 additions and 2 deletions
@@ -336,12 +336,12 @@ class FunctionDescriptorResolver(
for (i in valueParameters.indices) {
val valueParameter = valueParameters[i]
val typeReference = valueParameter.typeReference
val expectedType = expectedParameterTypes?.let { if (i < it.size) it[i] else null }
val expectedType = expectedParameterTypes?.let { if (i < it.size) it[i] else null }?.takeUnless { TypeUtils.noExpectedType(it) }
val type: KotlinType
if (typeReference != null) {
type = typeResolver.resolveType(parameterScope, typeReference, trace, true)
if (expectedType != null && !TypeUtils.noExpectedType(expectedType)) {
if (expectedType != null) {
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(expectedType, type)) {
trace.report(EXPECTED_PARAMETER_TYPE_MISMATCH.on(valueParameter, expectedType))
}
@@ -0,0 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
val la = { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>a<!> -> }
val las = { <!UNUSED_ANONYMOUS_PARAMETER!>a<!>: Int -> }
val larg = { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>a<!> -> }(123)
val twoarg = { <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>a<!>, <!UNUSED_ANONYMOUS_PARAMETER!>b<!>: String, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>c<!> -> }(123, "asdf", 123)
@@ -0,0 +1,6 @@
package
public val la: (???) -> kotlin.Unit
public val larg: kotlin.Unit
public val las: (kotlin.Int) -> kotlin.Unit
public val twoarg: kotlin.Unit
@@ -8209,6 +8209,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt16016.kt")
public void testKt16016() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt16016.kt");
doTest(fileName);
}
@TestMetadata("kt2906.kt")
public void testKt2906() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");