diff --git a/compiler/testData/codegen/box/innerNested/kt3927.kt b/compiler/testData/codegen/box/innerNested/kt3927.kt new file mode 100644 index 00000000000..1e1efce9624 --- /dev/null +++ b/compiler/testData/codegen/box/innerNested/kt3927.kt @@ -0,0 +1,23 @@ +//KT-3927 Inner class cannot be instantiated with child instance of outer class + +abstract class Base { + inner class Inner { + fun o() = "O" + fun k() = "K" + } +} + +class Child : Base() + +fun box(): String { + var result = "" + result += Child().Inner().o() + + fun Child.f() { + result += Inner().k() + } + Child().f() + + return result +} + diff --git a/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/JavaClass.java b/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/JavaClass.java new file mode 100644 index 00000000000..bbcfc7d5ffe --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/JavaClass.java @@ -0,0 +1,5 @@ +public class JavaClass { + public String getO() { + return "O"; + } +} diff --git a/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/main.kt b/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/main.kt new file mode 100644 index 00000000000..60a7c672f9c --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/main.kt @@ -0,0 +1,7 @@ +// KT-9522 Allow invoke convention for synthetic property + +operator fun String.invoke() = this + "K" + +fun box(): String { + return JavaClass().o(); +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt new file mode 100644 index 00000000000..88f47ce461b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// KT-10036 Ambiguous overload cannot be resolved when using a member function reference in Beta 2, that worked in Beta 1 + +class OverloadTest { + fun foo(bar: Boolean) {} + fun foo(bar: Any?) {} +} + +object Literal + +inline fun OverloadTest.overload(value: T?, function: OverloadTest.(T) -> Unit) { + if (value == null) foo(Literal) else function(value) +} + +// Overload resolution ambiguity +fun OverloadTest.overloadBoolean(value: Boolean?) = overload(value, OverloadTest::foo) + +// Works fine +fun OverloadTest.overloadBoolean2(value: Boolean?) = overload(value) { foo(it) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.txt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.txt new file mode 100644 index 00000000000..ae3bf007624 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.txt @@ -0,0 +1,21 @@ +package + +public inline fun OverloadTest.overload(/*0*/ value: T?, /*1*/ function: OverloadTest.(T) -> kotlin.Unit): kotlin.Unit +public fun OverloadTest.overloadBoolean(/*0*/ value: kotlin.Boolean?): kotlin.Unit +public fun OverloadTest.overloadBoolean2(/*0*/ value: kotlin.Boolean?): kotlin.Unit + +public object Literal { + private constructor Literal() + 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 +} + +public final class OverloadTest { + public constructor OverloadTest() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ bar: kotlin.Any?): kotlin.Unit + public final fun foo(/*0*/ bar: kotlin.Boolean): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/overload/kt7440.kt b/compiler/testData/diagnostics/tests/overload/kt7440.kt new file mode 100644 index 00000000000..afc5a210323 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt7440.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// KT-7440 Cannot complete type inference if two extension functions for interface hierarchy + +package inferenceagain + +interface Base +interface Derived : Base + +fun , T : Any> Base.maxBy(f: (T) -> R): T? = null +fun , T : Any> Derived.maxBy(f: (T) -> R): T? = null + +fun derivedOf(vararg members: T): Derived = null!! + +fun x(l: Derived) { + derivedOf(1, 2, 3).maxBy { it } // works + derivedOf(1, 2, 3).maxBy { it } // should work +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt7440.txt b/compiler/testData/diagnostics/tests/overload/kt7440.txt new file mode 100644 index 00000000000..26d64f77562 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt7440.txt @@ -0,0 +1,20 @@ +package + +package inferenceagain { + public fun derivedOf(/*0*/ vararg members: T /*kotlin.Array*/): inferenceagain.Derived + public fun x(/*0*/ l: inferenceagain.Derived): kotlin.Unit + public fun , /*1*/ T : kotlin.Any> inferenceagain.Base.maxBy(/*0*/ f: (T) -> R): T? + public fun , /*1*/ T : kotlin.Any> inferenceagain.Derived.maxBy(/*0*/ f: (T) -> R): T? + + public interface Base { + 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 + } + + public interface Derived : inferenceagain.Base { + 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/testData/diagnostics/tests/regressions/kt9682.kt b/compiler/testData/diagnostics/tests/regressions/kt9682.kt new file mode 100644 index 00000000000..db72922dbd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9682.kt @@ -0,0 +1,28 @@ +// KT-9682 Overload Resolution Ambiguity after casting to Interface + +open class Foo { + fun bar(): Foo { + return this + } +} + +class Foo2 : Foo(), IFoo + +interface IFoo { + fun bar(): Foo +} + +fun test() { + val foo : Foo = Foo2() + foo as IFoo + foo.bar() // Should be resolved to Foo#bar +} + +interface IFoo2 { + fun bar(): IFoo2 +} + +fun test2(foo: Foo) { + foo as IFoo2 + foo.bar() // should be ambiguity +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt9682.txt b/compiler/testData/diagnostics/tests/regressions/kt9682.txt new file mode 100644 index 00000000000..26f659e0403 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9682.txt @@ -0,0 +1,34 @@ +package + +public fun test(): kotlin.Unit +public fun test2(/*0*/ foo: Foo): kotlin.Unit + +public open class Foo { + public constructor Foo() + public final fun bar(): Foo + 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 +} + +public final class Foo2 : Foo, IFoo { + public constructor Foo2() + public final override /*2*/ /*fake_override*/ fun bar(): Foo + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IFoo { + public abstract fun bar(): Foo + 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 +} + +public interface IFoo2 { + public abstract fun bar(): IFoo2 + 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/testData/diagnostics/tests/regressions/kt9808.kt b/compiler/testData/diagnostics/tests/regressions/kt9808.kt new file mode 100644 index 00000000000..1e8ce4f51a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9808.kt @@ -0,0 +1,8 @@ +// KT-9808 Extension function on object for new resolve +object O + +val foo: O.() -> Unit = null!! + +fun test() { + O.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt9808.txt b/compiler/testData/diagnostics/tests/regressions/kt9808.txt new file mode 100644 index 00000000000..0e6def24ba0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9808.txt @@ -0,0 +1,11 @@ +package + +public val foo: O.() -> kotlin.Unit +public fun test(): kotlin.Unit + +public object O { + private constructor O() + 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/testData/diagnostics/tests/resolve/invoke/kt9517.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.kt new file mode 100644 index 00000000000..94d993d12b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.kt @@ -0,0 +1,16 @@ + +//KT-9517 Wrong resolve for invoke convention after smart cast +open class A { + open val foo: () -> Number = null!! +} + +class B: A() { + override val foo: () -> Int + get() = null!! +} + +fun test(a: A) { + if (a is B) { + val foo: Int = a.foo() // B::foo + invoke() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.txt b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.txt new file mode 100644 index 00000000000..5e84a038f59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.txt @@ -0,0 +1,19 @@ +package + +public fun test(/*0*/ a: A): kotlin.Unit + +public open class A { + public constructor A() + public open val foo: () -> kotlin.Number + 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 +} + +public final class B : A { + public constructor B() + public open override /*1*/ val foo: () -> kotlin.Int + 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/testData/diagnostics/tests/resolve/priority/kt9810.kt b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.kt new file mode 100644 index 00000000000..db63cc5e5bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// KT-9810 Local variable vs property from implicit receiver + +class A { + val foo = 2 +} + +fun test(foo: String) { + with(A()) { + val g: String = foo // locals win + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/kt9810.txt b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.txt new file mode 100644 index 00000000000..b946ef568b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.txt @@ -0,0 +1,11 @@ +package + +public fun test(/*0*/ foo: kotlin.String): kotlin.Unit + +public final class A { + public constructor A() + public final val foo: kotlin.Int = 2 + 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/testData/diagnostics/testsWithStdLib/regression/kt9345.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.kt new file mode 100644 index 00000000000..732617e137e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.kt @@ -0,0 +1,3 @@ +//KT-9345 Type inference failure + +fun Class<*>.foo(): Any? = kotlin.objectInstance \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.txt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.txt new file mode 100644 index 00000000000..7f5a2be6db5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.txt @@ -0,0 +1,3 @@ +package + +public fun java.lang.Class<*>.foo(): kotlin.Any? diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index f78f2f39726..fe40568e141 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -2093,6 +2093,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt10036.kt") + public void testKt10036() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt"); + doTest(fileName); + } + @TestMetadata("kt9601.kt") public void testKt9601() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt9601.kt"); @@ -11475,6 +11481,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt7440.kt") + public void testKt7440() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/kt7440.kt"); + doTest(fileName); + } + @TestMetadata("OverloadFunRegularAndExt.kt") public void testOverloadFunRegularAndExt() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/OverloadFunRegularAndExt.kt"); @@ -13632,6 +13644,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt9682.kt") + public void testKt9682() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt9682.kt"); + doTest(fileName); + } + + @TestMetadata("kt9808.kt") + public void testKt9808() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt9808.kt"); + doTest(fileName); + } + @TestMetadata("noThis.kt") public void testNoThis() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/noThis.kt"); @@ -13952,6 +13976,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt9517.kt") + public void testKt9517() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/kt9517.kt"); + doTest(fileName); + } + @TestMetadata("kt9805.kt") public void testKt9805() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/kt9805.kt"); @@ -14204,6 +14234,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt9810.kt") + public void testKt9810() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/priority/kt9810.kt"); + doTest(fileName); + } + @TestMetadata("kt9965.kt") public void testKt9965() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/priority/kt9965.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 0930f8f302e..53e901efb72 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1008,6 +1008,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.kt"); doTest(fileName); } + + @TestMetadata("kt9345.kt") + public void testKt9345() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/reified") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 68f0ec1ab23..39d64e1db8a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4699,6 +4699,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt3927.kt") + public void testKt3927() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/kt3927.kt"); + doTest(fileName); + } + @TestMetadata("kt5363.kt") public void testKt5363() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/kt5363.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index cf62eb395b7..e7294c5d240 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -113,6 +113,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("invokeOnSyntheticProperty") + public void testInvokeOnSyntheticProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/invokeOnSyntheticProperty/"); + doTestWithJava(fileName); + } + @TestMetadata("jvmName") public void testJvmName() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/jvmName/");