diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled1.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled1.kt new file mode 100644 index 00000000000..de9ff4bbd7b --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled1.kt @@ -0,0 +1,8 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:-SamConversionPerArgument +// PROBLEM: none + +fun test(r1: Runnable, r2: Runnable) {} + +fun usage(r1: Runnable) { + test(r1, Runnable {}) +} diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled2.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled2.kt new file mode 100644 index 00000000000..82ecff5437a --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled2.kt @@ -0,0 +1,12 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:-SamConversionPerArgument +// PROBLEM: none + +fun interface KtRunnable { + fun run() +} + +fun test(r1: KtRunnable, r2: KtRunnable) {} + +fun usage(r1: KtRunnable) { + test(r1, KtRunnable {}) +} diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled3.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled3.kt new file mode 100644 index 00000000000..83b4b56f196 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled3.kt @@ -0,0 +1,8 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:-SamConversionPerArgument +// PROBLEM: none + +fun test(r1: Runnable, r2: Runnable) {} + +fun usage() { + test(Runnable { return@Runnable }, Runnable {}) +} diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn1.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn1.kt new file mode 100644 index 00000000000..2c7ace865e4 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn1.kt @@ -0,0 +1,7 @@ +// PROBLEM: none + +fun test(r: Runnable) {} + +fun usage() { + test(Runnable { return@Runnable }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn2.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn2.kt new file mode 100644 index 00000000000..d8b97b19429 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn2.kt @@ -0,0 +1,7 @@ +// PROBLEM: none + +fun test(r: Runnable) {} + +fun usage() { + test(Runnable a@{ return@a }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.1.java b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.1.java new file mode 100644 index 00000000000..9f6bcc0da36 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.1.java @@ -0,0 +1,12 @@ +public interface JavaTest { + interface FunInterface1 { + void test(); + } + + interface FunInterface2 { + int test(); + } + + void foo(FunInterface1 f1); + void foo(FunInterface2 f2); +} diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.kt new file mode 100644 index 00000000000..5ae7d3b44f2 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.kt @@ -0,0 +1,5 @@ +// PROBLEM: none + +fun usage(javaTest: JavaTest) { + javaTest.foo(JavaTest.FunInterface1 { 10 }) // foo call will be ambiguous without SAM constructor +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.1.java b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.1.java new file mode 100644 index 00000000000..24e29fe525f --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.1.java @@ -0,0 +1,7 @@ +public interface JavaTest { + interface FunInterface1 { + void test(); + } + + void foo(FunInterface1 f1); +} diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.kt new file mode 100644 index 00000000000..17df1e834f1 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.kt @@ -0,0 +1,7 @@ +// PROBLEM: none + +fun JavaTest.usage() { + fun foo(a: () -> Unit) {} + + foo(JavaTest.FunInterface1 { 10 }) // local foo will be used without SAM constructor +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.1.java b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.1.java new file mode 100644 index 00000000000..1d6c8e85e29 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.1.java @@ -0,0 +1,17 @@ +public interface Interfaces { + interface FunInterface1 { + void test(); + } + + interface FunInterface2 { + void test(); + } + + interface InterfaceWithMethod1 { + void foo(FunInterface1 f1); + } + + interface InterfaceWithMethod2 { + void foo(FunInterface2 f1); + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.kt new file mode 100644 index 00000000000..f60887c63aa --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.kt @@ -0,0 +1,11 @@ +// PROBLEM: none + +fun with(t: T, action: T.() -> R) = t.action() + +private fun usage(int1: Interfaces.InterfaceWithMethod1, int2: Interfaces.InterfaceWithMethod2) { + with(int1) { + with(int2) { + foo(Interfaces.FunInterface1 { }) // removing SAM constructor will change resolution to InterfaceWithMethod2::foo + } + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index f5d2be81a30..a7201443136 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -7866,11 +7866,51 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSamConstructor"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); } + @TestMetadata("conversionPerArgumentDisabled1.kt") + public void testConversionPerArgumentDisabled1() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled1.kt"); + } + + @TestMetadata("conversionPerArgumentDisabled2.kt") + public void testConversionPerArgumentDisabled2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled2.kt"); + } + + @TestMetadata("conversionPerArgumentDisabled3.kt") + public void testConversionPerArgumentDisabled3() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/conversionPerArgumentDisabled3.kt"); + } + + @TestMetadata("labeledReturn1.kt") + public void testLabeledReturn1() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn1.kt"); + } + + @TestMetadata("labeledReturn2.kt") + public void testLabeledReturn2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/labeledReturn2.kt"); + } + @TestMetadata("nestedInterface.kt") public void testNestedInterface() throws Exception { runTest("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt"); } + @TestMetadata("resolutionAmbiguity1.kt") + public void testResolutionAmbiguity1() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity1.kt"); + } + + @TestMetadata("resolutionAmbiguity2.kt") + public void testResolutionAmbiguity2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity2.kt"); + } + + @TestMetadata("resolutionAmbiguity3.kt") + public void testResolutionAmbiguity3() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/resolutionAmbiguity3.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt");