From b8c09107240cbe47ab9da88e4cda18ea98a38aa9 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 26 Mar 2018 14:37:32 +0300 Subject: [PATCH] Add one more test on delegated properties to check NI --- .../inference/delegateExpressionAsLambda.kt | 22 +++++++++++++++++++ .../inference/delegateExpressionAsLambda.txt | 22 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 6 +++++ 4 files changed, 56 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.txt diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt new file mode 100644 index 00000000000..16a72a896cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +fun test(i: Int) { + val bad by myLazyDelegate { + createSample(i) { it.toString() } + } + + takeSample(bad) +} + +fun myLazyDelegate(i: () -> T): LazyDelegate = LazyDelegate(i()) + +class LazyDelegate(val v: T) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO() +} + +class Sample + +fun takeSample(g: Sample) {} +fun createSample(i: T, a: (T) -> S): Sample = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.txt new file mode 100644 index 00000000000..adcd11b711a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.txt @@ -0,0 +1,22 @@ +package + +public fun createSample(/*0*/ i: T, /*1*/ a: (T) -> S): Sample +public fun myLazyDelegate(/*0*/ i: () -> T): LazyDelegate +public fun takeSample(/*0*/ g: Sample): kotlin.Unit +public fun test(/*0*/ i: kotlin.Int): kotlin.Unit + +public final class LazyDelegate { + public constructor LazyDelegate(/*0*/ v: T) + public final val v: T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Sample { + public constructor Sample() + 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/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 23281741cda..8f643667064 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6223,6 +6223,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegatedProperty/inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("delegateExpressionAsLambda.kt") + public void testDelegateExpressionAsLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt"); + doTest(fileName); + } + @TestMetadata("differentDelegatedExpressions.kt") public void testDifferentDelegatedExpressions() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 7f136af71b5..f7405478efd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -6223,6 +6223,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegatedProperty/inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("delegateExpressionAsLambda.kt") + public void testDelegateExpressionAsLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt"); + doTest(fileName); + } + @TestMetadata("differentDelegatedExpressions.kt") public void testDifferentDelegatedExpressions() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");