FIR: Fix SAM conversion for constructor calls
This commit is contained in:
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface FirSamResolver : FirSessionComponent {
|
||||
fun getFunctionTypeForPossibleSamType(type: ConeKotlinType): ConeKotlinType?
|
||||
fun shouldRunSamConversionForFunction(firNamedFunction: FirSimpleFunction): Boolean
|
||||
fun shouldRunSamConversionForFunction(firFunction: FirFunction<*>): Boolean
|
||||
fun getSamConstructor(firRegularClass: FirRegularClass): FirSimpleFunction?
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class FirSamResolverImpl(
|
||||
} as? ConeKotlinType
|
||||
}
|
||||
|
||||
override fun shouldRunSamConversionForFunction(firNamedFunction: FirSimpleFunction): Boolean {
|
||||
override fun shouldRunSamConversionForFunction(firFunction: FirFunction<*>): Boolean {
|
||||
// TODO: properly support, see org.jetbrains.kotlin.load.java.sam.JvmSamConversionTransformer.shouldRunSamConversionForFunction
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.inferenceContext
|
||||
@@ -305,8 +305,8 @@ private fun Candidate.getExpectedTypeWithSAMConversion(
|
||||
): ConeKotlinType? {
|
||||
if (candidateExpectedType.isBuiltinFunctionalType(session)) return null
|
||||
// TODO: if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument)) return null
|
||||
val firNamedFunction = symbol.fir as? FirSimpleFunction ?: return null
|
||||
if (!samResolver.shouldRunSamConversionForFunction(firNamedFunction)) return null
|
||||
val firFunction = symbol.fir as? FirFunction<*> ?: return null
|
||||
if (!samResolver.shouldRunSamConversionForFunction(firFunction)) return null
|
||||
|
||||
val argumentIsFunctional = when ((argument as? FirWrappedArgumentExpression)?.expression ?: argument) {
|
||||
is FirAnonymousFunction, is FirCallableReferenceAccess -> true
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
FILE: main.kt
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
<Inapplicable(INAPPLICABLE): [/Foo.Foo]>#(<L> = Foo@fun <anonymous>(): R|ERROR CLASS: Unresolved name: it| {
|
||||
^ <Unresolved name: it>#
|
||||
}
|
||||
)
|
||||
}
|
||||
+1
-1
@@ -13,5 +13,5 @@ public class Foo {
|
||||
// FILE: main.kt
|
||||
|
||||
fun test() {
|
||||
<!INAPPLICABLE_CANDIDATE!>Foo<!> { <!UNRESOLVED_REFERENCE!>it<!> }
|
||||
Foo { it }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
FILE: main.kt
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
R|/Foo.Foo|(<L> = Foo@fun <anonymous>(it: R|kotlin/Boolean|): R|kotlin/Boolean| {
|
||||
^ R|<local>/it|
|
||||
}
|
||||
)
|
||||
}
|
||||
+5
-5
@@ -1176,11 +1176,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/propertyFromJavaPlusAssign.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samConversionInConstructorCall.kt")
|
||||
public void testSamConversionInConstructorCall() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticsVsNormalProperties.kt")
|
||||
public void testSyntheticsVsNormalProperties() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt");
|
||||
@@ -1285,6 +1280,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/runnable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samConversionInConstructorCall.kt")
|
||||
public void testSamConversionInConstructorCall() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samSupertype.kt")
|
||||
public void testSamSupertype() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/samSupertype.kt");
|
||||
|
||||
Generated
+5
-5
@@ -1176,11 +1176,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/propertyFromJavaPlusAssign.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samConversionInConstructorCall.kt")
|
||||
public void testSamConversionInConstructorCall() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticsVsNormalProperties.kt")
|
||||
public void testSyntheticsVsNormalProperties() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt");
|
||||
@@ -1285,6 +1280,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/runnable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samConversionInConstructorCall.kt")
|
||||
public void testSamConversionInConstructorCall() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("samSupertype.kt")
|
||||
public void testSamSupertype() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/samConversions/samSupertype.kt");
|
||||
|
||||
+1
-1
@@ -18,6 +18,6 @@ public class Observable<T> {
|
||||
|
||||
import j.*
|
||||
|
||||
class K : <!INAPPLICABLE_CANDIDATE!>Observable<String><!>({})
|
||||
class K : Observable<String>({})
|
||||
|
||||
class J : Observable<String>(null)
|
||||
|
||||
@@ -14,5 +14,5 @@ public class Observable<T> {
|
||||
typealias ObservableAlias<T> = Observable<T>
|
||||
typealias ObservableIntAlias = Observable<Int>
|
||||
|
||||
class A : <!INAPPLICABLE_CANDIDATE!>ObservableAlias<String><!>({})
|
||||
class B : <!INAPPLICABLE_CANDIDATE!>ObservableIntAlias<!>({})
|
||||
class A : ObservableAlias<String>({})
|
||||
class B : ObservableIntAlias({})
|
||||
|
||||
+1
-1
@@ -13,5 +13,5 @@ public class J {
|
||||
package test
|
||||
|
||||
fun test() {
|
||||
<!INAPPLICABLE_CANDIDATE!>J<!>("", r = { }, z = false)
|
||||
J("", r = { }, z = false)
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ public class A<E> {
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo() {
|
||||
val result: A<String> = <!INAPPLICABLE_CANDIDATE!>A<!><String> { x, y -> 1 }
|
||||
val result: A<String> = A<String> { x, y -> 1 }
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,10 +36,10 @@ fun main(x2: Runnable) {
|
||||
Test.foo1(x2, *arrayOf(""))
|
||||
|
||||
val i1 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf())
|
||||
val i2 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, *arrayOf())
|
||||
val i2 = Test({}, *arrayOf())
|
||||
val i3 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, x3)
|
||||
val i4 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf(""))
|
||||
val i5 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, *arrayOf(""))
|
||||
val i5 = Test({}, {}, *arrayOf(""))
|
||||
val i6 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, arrayOf())
|
||||
|
||||
i1.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, arrayOf())
|
||||
|
||||
Vendored
+11
-11
@@ -36,19 +36,19 @@ fun main(x2: Runnable) {
|
||||
Test.foo1(x2, *arrayOf(""))
|
||||
|
||||
val i1 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf())
|
||||
val i2 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, *arrayOf())
|
||||
val i2 = Test({}, *arrayOf())
|
||||
val i3 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, x3)
|
||||
val i4 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf(""))
|
||||
val i5 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, *arrayOf(""))
|
||||
val i5 = Test({}, {}, *arrayOf(""))
|
||||
val i6 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, arrayOf())
|
||||
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, arrayOf())
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, *arrayOf())
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, x2, arrayOf())
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>(x2, {}, *arrayOf())
|
||||
i2.<!INAPPLICABLE_CANDIDATE!>foo2<!>({}, {}, arrayOf())
|
||||
i2.foo2({}, {}, *arrayOf())
|
||||
i2.<!INAPPLICABLE_CANDIDATE!>foo2<!>({}, x2, arrayOf())
|
||||
i2.foo2(x2, {}, *arrayOf())
|
||||
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, arrayOf(""))
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, *x3)
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>({}, x2, x3)
|
||||
i2.<!UNRESOLVED_REFERENCE!>foo2<!>(x2, {}, *arrayOf(""))
|
||||
}
|
||||
i2.<!INAPPLICABLE_CANDIDATE!>foo2<!>({}, {}, arrayOf(""))
|
||||
i2.foo2({}, {}, *x3)
|
||||
i2.<!INAPPLICABLE_CANDIDATE!>foo2<!>({}, x2, x3)
|
||||
i2.foo2(x2, {}, *arrayOf(""))
|
||||
}
|
||||
|
||||
+3
-3
@@ -36,10 +36,10 @@ fun main(x2: Runnable) {
|
||||
Test.foo1(x2, *arrayOf(""))
|
||||
|
||||
val i1 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf())
|
||||
val i2 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, *arrayOf())
|
||||
val i2 = Test({}, *arrayOf())
|
||||
val i3 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, x3)
|
||||
val i4 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, arrayOf(""))
|
||||
val i5 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, *arrayOf(""))
|
||||
val i5 = Test({}, {}, *arrayOf(""))
|
||||
val i6 = <!INAPPLICABLE_CANDIDATE!>Test<!>({}, {}, arrayOf())
|
||||
|
||||
i1.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, arrayOf())
|
||||
@@ -51,4 +51,4 @@ fun main(x2: Runnable) {
|
||||
i1.<!UNRESOLVED_REFERENCE!>foo2<!>({}, {}, *x3)
|
||||
i1.<!UNRESOLVED_REFERENCE!>foo2<!>({}, x2, x3)
|
||||
i1.<!UNRESOLVED_REFERENCE!>foo2<!>(x2, {}, *arrayOf(""))
|
||||
}
|
||||
}
|
||||
|
||||
+9
-6
@@ -1,14 +1,17 @@
|
||||
FILE fqName:<root> fileName:/samConversionInGenericConstructorCall.kt
|
||||
FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>) returnType:IrErrorType
|
||||
FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>) returnType:<root>.C<kotlin.String?>
|
||||
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1<kotlin.String, kotlin.String>): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/C.C]>#' type=IrErrorType
|
||||
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1<kotlin.String, kotlin.String>): <root>.C<kotlin.String?> declared in <root>'
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (jxx: <root>.J<X of <uninitialized parent>?, X of <uninitialized parent>?>?) declared in <root>.C' type=<root>.C<kotlin.String?> origin=null
|
||||
<class: X>: kotlin.String?
|
||||
jxx: GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
|
||||
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
|
||||
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/C.C]>#' type=IrErrorType
|
||||
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (jxx: <root>.J<X of <uninitialized parent>?, X of <uninitialized parent>?>?) declared in <root>.C' type=<root>.C<kotlin.String?> origin=null
|
||||
<class: X>: kotlin.String?
|
||||
jxx: TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
|
||||
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
|
||||
|
||||
Vendored
+6
-8
@@ -4,7 +4,7 @@ FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
|
||||
VALUE_PARAMETER name:f2 index:1 type:kotlin.Function1<kotlin.Int, kotlin.String>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test3 (f1: kotlin.Function1<kotlin.String, kotlin.String>, f2: kotlin.Function1<kotlin.Int, kotlin.String>): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Unresolved name: D>#' type=IrErrorType
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/C.D.D]>#' type=IrErrorType
|
||||
GET_VAR 'f2: kotlin.Function1<kotlin.Int, kotlin.String> declared in <root>.test3' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=null
|
||||
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer<T1 of <root>.Outer>
|
||||
@@ -75,18 +75,16 @@ FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
|
||||
VALUE_PARAMETER name:g index:1 type:kotlin.Function1<kotlin.Any, kotlin.String>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test4 (f: kotlin.Function1<kotlin.String, kotlin.String>, g: kotlin.Function1<kotlin.Any, kotlin.String>): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Unresolved name: Inner>#' type=IrErrorType
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/Outer.Inner.Inner]>#' type=IrErrorType
|
||||
GET_VAR 'g: kotlin.Function1<kotlin.Any, kotlin.String> declared in <root>.test4' type=kotlin.Function1<kotlin.Any, kotlin.String> origin=null
|
||||
FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.Int>) returnType:IrErrorType
|
||||
FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.Int>) returnType:<root>.G<kotlin.String?>
|
||||
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.Int>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1<kotlin.String, kotlin.Int>): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/G.G]>#' type=IrErrorType
|
||||
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.Int> declared in <root>.testGenericJavaCtor1' type=kotlin.Function1<kotlin.String, kotlin.Int> origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1<kotlin.String, kotlin.Int>): <root>.G<kotlin.String?> declared in <root>'
|
||||
ERROR_EXPR 'Cannot bind 2 type arguments to ??? call with 1 type parameters' type=<root>.G<kotlin.String?>
|
||||
FUN name:testGenericJavaCtor2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.Int> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.Int>
|
||||
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Any origin=null
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/G.G]>#' type=IrErrorType
|
||||
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Function1<kotlin.String, kotlin.Int> origin=null
|
||||
ERROR_EXPR 'Cannot bind 2 type arguments to ??? call with 1 type parameters' type=<root>.G<kotlin.String?>
|
||||
|
||||
Reference in New Issue
Block a user