From 58e7923218d4491bd1abbf803b1f58038a45678c Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 17 Jul 2015 12:38:44 +0300 Subject: [PATCH] Use substituted return type for SAM adapeter of constructor #KT-7282 Fixed --- .../load/java/sam/SingleAbstractMethodUtils.java | 2 +- .../tests/platformTypes/samAdapterInConstructor.kt | 14 ++++++++++++++ .../platformTypes/samAdapterInConstructor.txt | 11 +++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.txt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java index 92a897733e0..5e3f2dcb8f2 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java @@ -223,7 +223,7 @@ public class SingleAbstractMethodUtils { @Nullable JetType returnType ) { result.initialize(typeParameters, valueParameters, original.getVisibility()); - result.setReturnType(result.getContainingDeclaration().getDefaultType()); + result.setReturnType(returnType); } }); } diff --git a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt new file mode 100644 index 00000000000..3e752b40890 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// FILE: A.java +import java.util.Comparator; + +public class A { + public A(Comparator comparator) {} +} + +// FILE: main.kt + +fun foo() { + val result: A = A { x, y -> 1 } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.txt b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.txt new file mode 100644 index 00000000000..7db363d32ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.txt @@ -0,0 +1,11 @@ +package + +internal fun foo(): kotlin.Unit + +public open class A { + public /*synthesized*/ constructor A(/*0*/ comparator: ((E!, E!) -> kotlin.Int)!) + public constructor A(/*0*/ comparator: java.util.Comparator!) + 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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 77b719cee76..03ba06db697 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -10059,6 +10059,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("samAdapterInConstructor.kt") + public void testSamAdapterInConstructor() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt"); + doTest(fileName); + } + @TestMetadata("samConstructor.kt") public void testSamConstructor() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/samConstructor.kt");