[Spec tests] Add tests for receivers prioritization
This commit is contained in:
committed by
Victor Petukhov
parent
3b35374186
commit
157e33d08b
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-268
|
||||
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: implicit this receiver has higher priority than any companion object receiver
|
||||
*/
|
||||
|
||||
|
||||
class Case1() : Case1Base() {
|
||||
|
||||
companion object foo{
|
||||
var isCompanionObjectReceiverCalled = false
|
||||
operator fun invoke() {}
|
||||
fun foo() {
|
||||
this.isCompanionObjectReceiverCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun case() {
|
||||
foo() // resolved (1)
|
||||
}
|
||||
}
|
||||
|
||||
open class Case1Base {
|
||||
var isImplicitReceiverCalled = false
|
||||
|
||||
fun foo() {
|
||||
this.isImplicitReceiverCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val test = Case1()
|
||||
test.case()
|
||||
if (test.isImplicitReceiverCalled && !Case1.isCompanionObjectReceiverCalled)
|
||||
return "OK"
|
||||
return "NOK"
|
||||
}
|
||||
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-268
|
||||
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: implicit this receiver has higher priority than any companion object receiver
|
||||
*/
|
||||
|
||||
|
||||
class Case1() : Case1Base() {
|
||||
var isImplicitReceiverCalled = false
|
||||
|
||||
fun foo() {
|
||||
this.isImplicitReceiverCalled = true
|
||||
} // (1)
|
||||
|
||||
fun case() {
|
||||
foo() // resolved (1)
|
||||
}
|
||||
}
|
||||
|
||||
open class Case1Base {
|
||||
|
||||
companion object foo{
|
||||
var isCompanionObjectReceiverCalled = false
|
||||
operator fun invoke() {}
|
||||
fun foo() {
|
||||
this.isCompanionObjectReceiverCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Case1()
|
||||
test.case()
|
||||
if (test.isImplicitReceiverCalled && !Case1Base.isCompanionObjectReceiverCalled)
|
||||
return "OK"
|
||||
return "NOK"
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-268
|
||||
* PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects;
|
||||
*/
|
||||
|
||||
class Case() : CaseBase() {
|
||||
|
||||
companion object foo{
|
||||
var isCaseCompanionCalled = false
|
||||
fun foo(){isCaseCompanionCalled = true}
|
||||
}
|
||||
}
|
||||
|
||||
open class CaseBase {
|
||||
companion object foo {
|
||||
var isCaseBaseReceiverCalled = false
|
||||
fun foo() { this.isCaseBaseReceiverCalled = true }
|
||||
// operator fun invoke() {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Case.foo.foo()
|
||||
if (!CaseBase.isCaseBaseReceiverCalled && Case.isCaseCompanionCalled)
|
||||
return "OK"
|
||||
return "NOK"
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-268
|
||||
* PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects;
|
||||
*/
|
||||
|
||||
class Case() : CaseBase() {
|
||||
|
||||
companion object foo{
|
||||
var isCaseCompanionCalled = false
|
||||
fun foo(){isCaseCompanionCalled = true}
|
||||
}
|
||||
|
||||
fun test(): String{
|
||||
foo.foo()
|
||||
if (!isCaseBaseReceiverCalled && isCaseCompanionCalled)
|
||||
return "OK"
|
||||
return "NOK"
|
||||
}
|
||||
}
|
||||
|
||||
open class CaseBase {
|
||||
companion object foo {
|
||||
var isCaseBaseReceiverCalled = false
|
||||
fun foo() { this.isCaseBaseReceiverCalled = true }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Case().test()
|
||||
}
|
||||
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-268
|
||||
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 4
|
||||
* RELEVANT PLACES: overload-resolution, receivers -> paragraph 5 -> sentence 3
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Superclass companion object receivers are prioritized according to the inheritance order
|
||||
*/
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val case0 =CaseBase0().case0()
|
||||
val case1 =CaseBase1().case1()
|
||||
val case2 =CaseBase2().case2()
|
||||
if (case0 && case1 && case2)
|
||||
return "OK"
|
||||
return "NOK"
|
||||
}
|
||||
|
||||
class CaseBase2() : CaseBase1() {
|
||||
|
||||
companion object foo {
|
||||
var isCaseCompanionCalled = false
|
||||
fun foo() {
|
||||
isCaseCompanionCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun case2(): Boolean {
|
||||
foo.foo()
|
||||
val res = !isCaseBase0ReceiverCalled && !isCaseBaseReceiverCalled && isCaseCompanionCalled
|
||||
isCaseCompanionCalled = false
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
open class CaseBase1 : CaseBase0() {
|
||||
companion object foo {
|
||||
var isCaseBaseReceiverCalled = false
|
||||
fun foo() {
|
||||
this.isCaseBaseReceiverCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun case1(): Boolean {
|
||||
foo.foo()
|
||||
val res = !isCaseBase0ReceiverCalled && CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled
|
||||
isCaseBaseReceiverCalled = false
|
||||
return res
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open class CaseBase0 {
|
||||
companion object foo {
|
||||
var isCaseBase0ReceiverCalled = false
|
||||
fun foo() {
|
||||
this.isCaseBase0ReceiverCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun case0(): Boolean {
|
||||
foo.foo()
|
||||
val res = isCaseBase0ReceiverCalled && !CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled
|
||||
isCaseBase0ReceiverCalled = false
|
||||
return res
|
||||
}
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"5": {
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "implicit this receiver has higher priority than any companion object receiver",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "implicit this receiver has higher priority than any companion object receiver",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "Current class companion object receiver has higher priority than any of the superclass companion objects;",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "Superclass companion object receivers are prioritized according to the inheritance order",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "Current class companion object receiver has higher priority than any of the superclass companion objects;",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"4": [
|
||||
{
|
||||
"specVersion": "0.1-268",
|
||||
"casesNumber": 0,
|
||||
"description": "Superclass companion object receivers are prioritized according to the inheritance order",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user