[Spec tests] Add test for infix fun + KT-36786

This commit is contained in:
anastasiia.spaseeva
2020-02-17 17:50:43 +03:00
committed by Victor Petukhov
parent c9bb994fb5
commit 4301744d2d
8 changed files with 389 additions and 0 deletions
@@ -0,0 +1,37 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: infix calls for properties
*/
class C() {
var isInvokeCalled = false
infix operator fun invoke(i: Int) { isInvokeCalled = true } //(1)
}
class B() {
val memberValC
get() = c
}
val c = C()
val B.extensionValC: C
get() = c
fun box(): String{
val b = B()
b memberValC 3 //resolved to (1) o_O
if (b.memberValC.isInvokeCalled) {
c.isInvokeCalled = false
b extensionValC 4 //resolved to (1) o_O
if (b.extensionValC.isInvokeCalled)
return "OK"
}
return "NOK"
}
@@ -0,0 +1,14 @@
{
"4": {
"pos": {
"1": [
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "infix calls for properties",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call
* NUMBER: 1
* DESCRIPTION: Not null Smartcast doesn't work in case of property infix call
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-36786
*/
class C() {
infix operator fun invoke(i: Int) { } //(1)
}
class B(val memberValCNull: C? = null) {
infix fun bar(i: Int) {}
}
// TESTCASE NUMBER: 1
fun case1() {
val b: B = B()
// b memberValCNull 1 //nok (UNSAFE_INFIX_CALL)
// b.memberValCNull.invoke(1) //nok (UNSAFE_CALL)
if (b.memberValCNull != null) {
b <!UNSAFE_INFIX_CALL!>memberValCNull<!> 1 //nok (UNSAFE_INFIX_CALL) !!!!
<!DEBUG_INFO_SMARTCAST!>b.memberValCNull<!>.invoke(2) //ok
b.<!UNSAFE_IMPLICIT_INVOKE_CALL!>memberValCNull<!>(3) //nok (UNSAFE_CALL) !!!
}
}
@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call
* NUMBER: 2
* DESCRIPTION: is-check Smartcast doesn't work in case of property infix call
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-36786
*/
class B(val memberVal: Any)
class C() {
infix operator fun invoke(i: Int) { } //(1)
}
// TESTCASE NUMBER: 1
fun case1() {
val b: B = B(C())
b <!UNRESOLVED_REFERENCE!>memberVal<!> 1 //nok UNRESOLVED_REFERENCE
b.memberVal.<!UNRESOLVED_REFERENCE!>invoke<!>(2) //nok UNRESOLVED_REFERENCE
b.<!FUNCTION_EXPECTED!>memberVal<!>(1) //nok FUNCTION_EXPECTED
if (b.memberVal is C) {
b <!UNRESOLVED_REFERENCE!>memberVal<!> 1 //nok UNRESOLVED_REFERENCE !!!!
<!DEBUG_INFO_SMARTCAST!>b.memberVal<!>.invoke(1) //ok
b.<!FUNCTION_EXPECTED!>memberVal<!>(1) //nok FUNCTION_EXPECTED !!!
<!DEBUG_INFO_SMARTCAST!>(b.memberVal)<!>(1) //ok
}
}
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call
* NUMBER: 3
* DESCRIPTION: "Unsafe" cast doesn't work in case of property infix call
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-36786
*/
class B(val memberVal: Any)
class C() {
infix operator fun invoke(i: Int) { } //(1)
}
// TESTCASE NUMBER: 1
fun case1() {
val b: B = B(C())
b <!UNRESOLVED_REFERENCE!>memberVal<!> 1 //nok UNRESOLVED_REFERENCE
b.memberVal.<!UNRESOLVED_REFERENCE!>invoke<!>(2) //nok UNRESOLVED_REFERENCE
b.<!FUNCTION_EXPECTED!>memberVal<!>(1) //nok FUNCTION_EXPECTED
b.memberVal as C
b <!UNRESOLVED_REFERENCE!>memberVal<!> 1 //nok UNRESOLVED_REFERENCE !!!!
<!DEBUG_INFO_SMARTCAST!>b.memberVal<!>.invoke(1) //ok
b.<!FUNCTION_EXPECTED!>memberVal<!>(1) //nok FUNCTION_EXPECTED !!!
<!DEBUG_INFO_SMARTCAST!>(b.memberVal)<!>(1) //ok
}
@@ -0,0 +1,109 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call
* NUMBER: 4
* DESCRIPTION: Local extension infix extension callables
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-36786
*/
// TESTCASE NUMBER: 1, 2
// FILE: infixLib.kt
package libPackage
class C() {
infix operator fun invoke(i: Int) {}
}
class B() {
val barC: C = TODO()
val B.<!EXTENSION_SHADOWED_BY_MEMBER!>barC<!>: C
get() = TODO()
infix fun fooC(i: Int) = {}
infix fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>fooC<!>(i: Int) =
{}
}
infix fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>fooC<!>(i: Int) = {}
val B.<!EXTENSION_SHADOWED_BY_MEMBER!>barC<!>: C
get() = TODO()
// FILE: TestCase1.kt
/*
* TESTCASE NUMBER: 1
* NOTE: should be resolved to member properties, others should be shadowed by member function
*/
package testPackInfix
import libPackage.C
import libPackage.B
import libPackage.*
fun case1() {
class Case() {
val B.<!EXTENSION_SHADOWED_BY_MEMBER!>barC<!>: C
get() = TODO()
fun case() {
val b = B()
<!DEBUG_INFO_CALL("fqName: libPackage.B.fooC; typeCall: infix function")!>b fooC 3<!>
<!DEBUG_INFO_CALL("fqName: libPackage.C.invoke; typeCall: variable&invoke")!>b barC 3<!>
}
}
fun case() {
val b = B()
<!DEBUG_INFO_CALL("fqName: libPackage.B.fooC; typeCall: infix function")!>b fooC 3<!>
<!DEBUG_INFO_CALL("fqName: libPackage.C.invoke; typeCall: variable&invoke")!>b barC 3<!>
}
}
// FILE: TestCase2.kt
/*
* TESTCASE NUMBER: 2
* NOTE: should be resolved to member properties, others should be shadowed by member property with invoke or by member function
*/
package testPackInfix
import libPackage.C
import libPackage.B
import libPackage.*
import libPackage.fooC
import libPackage.barC
/*should be shadowed by member function*/
infix fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>fooC<!>(i: Int) = {}
/*should be shadowed by member property with invoke*/
infix fun B.<!EXTENSION_FUNCTION_SHADOWED_BY_MEMBER_PROPERTY_WITH_INVOKE!>barC<!>(i: Int) = {}
/*should be shadowed by member property*/
val B.<!EXTENSION_SHADOWED_BY_MEMBER!>barC<!>: C
get() = TODO()
fun case2() {
class Case() {
/*should be shadowed by member property*/
val B.<!EXTENSION_SHADOWED_BY_MEMBER!>barC<!>: C
get() = TODO()
/*should be shadowed by member property with invoke*/
infix fun B.<!EXTENSION_FUNCTION_SHADOWED_BY_MEMBER_PROPERTY_WITH_INVOKE!>barC<!>(i: Int) = {}
/*should be shadowed by member function*/
infix fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>fooC<!>(i: Int) = {}
fun case() {
val b = B()
<!DEBUG_INFO_CALL("fqName: libPackage.B.fooC; typeCall: infix function")!>b fooC 3<!>
<!DEBUG_INFO_CALL("fqName: libPackage.C.invoke; typeCall: variable&invoke")!>b barC 3<!>
}
}
fun case() {
val b = B()
<!DEBUG_INFO_CALL("fqName: libPackage.B.fooC; typeCall: infix function")!>b fooC 3<!>
<!DEBUG_INFO_CALL("fqName: libPackage.C.invoke; typeCall: variable&invoke")!>b barC 3<!>
}
}
@@ -5931,5 +5931,77 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
} }
} }
} }
@TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Overload_resolution extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInOverload_resolution() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Building_the_overload_candidate_set_ocs extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInBuilding_the_overload_candidate_set_ocs() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Infix_function_call extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInInfix_function_call() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.kt")
public void test1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/1.kt");
}
@TestMetadata("2.kt")
public void test2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/2.kt");
}
@TestMetadata("3.kt")
public void test3() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/3.kt");
}
@TestMetadata("4.kt")
public void test4() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/4.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
}
}
}
}
} }
} }
@@ -3305,6 +3305,63 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution"), Pattern.compile("^(.+)\\.kt$"), null, true);
} }
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Building_the_overload_candidate_set_ocs extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInBuilding_the_overload_candidate_set_ocs() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Infix_function_call extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInInfix_function_call() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_4 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_4() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos/1.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/callables-and-invoke-convention") @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/callables-and-invoke-convention")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)