FIR: Fix scope intersection types

Otherwise overload resolution ambiguity is reported in the test
This commit is contained in:
Denis Zharkov
2020-01-29 17:35:47 +03:00
parent d28e1f156a
commit 47ecaa5b06
24 changed files with 114 additions and 61 deletions
+3 -3
View File
@@ -23,9 +23,9 @@ class WrongIncDec() {
fun testWrongIncDec() {
var x = WrongIncDec()
x++
<!AMBIGUITY!>++<!>x
++x
x--
<!AMBIGUITY!>--<!>x
--x
}
class UnitIncDec() {
@@ -43,4 +43,4 @@ fun testUnitIncDec() {
x = x--
x = ++x
x = --x
}
}
@@ -10,7 +10,7 @@ class C() {
fun test(a : Any?) {
if (a is B) {
if (a is C) {
a.<!AMBIGUITY!>bar<!>();
a.bar();
}
}
}
@@ -27,8 +27,8 @@ fun <T : CharSequence?> foo(x: T) {
x.length
if (x is String) {
x.<!AMBIGUITY!>length<!>
x?.<!AMBIGUITY!>length<!>
x.length
x?.length
x.bar1()
x.bar2()
@@ -31,6 +31,6 @@ import p.*
fun test(b: B<String>?) {
if (b is C) {
b?.<!AMBIGUITY!>foo<!>()
b?.foo()
}
}
@@ -33,6 +33,6 @@ import p.*
fun test(b: B?) {
if (b is C && b is D) {
b?.<!AMBIGUITY!>getParent<!>()
b?.getParent()
}
}
@@ -4,31 +4,31 @@ fun intBinEq() {
x += 1.toByte()
x += 1.toShort()
x += 1L
<!UNRESOLVED_REFERENCE!>x += 1f<!>
<!UNRESOLVED_REFERENCE!>x += 1.0<!>
x += 1f
x += 1.0
<!UNRESOLVED_REFERENCE!>x *= 'a'<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toByte()<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x *= 1L<!>
<!UNRESOLVED_REFERENCE!>x *= 1f<!>
<!UNRESOLVED_REFERENCE!>x *= 1.0<!>
x *= 1.toByte()
x *= 1.toShort()
x *= 1L
x *= 1f
x *= 1.0
}
fun shortBinEq() {
var x = 0.toShort()
<!UNRESOLVED_REFERENCE!>x += 'a'<!>
x += 1.toByte()
<!UNRESOLVED_REFERENCE!>x += 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x += 1L<!>
<!UNRESOLVED_REFERENCE!>x += 1f<!>
<!UNRESOLVED_REFERENCE!>x += 1.0<!>
x += 1.toShort()
x += 1L
x += 1f
x += 1.0
<!UNRESOLVED_REFERENCE!>x *= 'a'<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toByte()<!>
<!UNRESOLVED_REFERENCE!>x *= 1.toShort()<!>
<!UNRESOLVED_REFERENCE!>x *= 1L<!>
<!UNRESOLVED_REFERENCE!>x *= 1f<!>
<!UNRESOLVED_REFERENCE!>x *= 1.0<!>
x *= 1.toByte()
x *= 1.toShort()
x *= 1L
x *= 1f
x *= 1.0
}
class A {
@@ -37,7 +37,7 @@ fun main(
a.foo(it)
// Iterators
a.<!AMBIGUITY!>foo<!>(ml.<!AMBIGUITY!>iterator<!>())
a.foo(ml.iterator())
a.foo(l.iterator())
// Sets
@@ -15,7 +15,7 @@ interface IFoo {
fun test() {
val foo : Foo = Foo2()
foo as IFoo
foo.<!AMBIGUITY!>bar<!>() // Should be resolved to Foo#bar
foo.bar() // Should be resolved to Foo#bar
}
interface IFoo2 {
@@ -24,5 +24,5 @@ interface IFoo2 {
fun test2(foo: Foo) {
foo as IFoo2
foo.<!AMBIGUITY!>bar<!>() // should be ambiguity
}
foo.bar() // should be ambiguity
}
@@ -12,7 +12,7 @@ class C() {
fun test(a : Any?) {
if (a is B) {
if (a is C) {
a.<!AMBIGUITY!>bar<!>();
a.bar();
}
}
}
@@ -8,6 +8,6 @@ interface B {
fun test(c: Any) {
if (c is B && c is A) {
c.<!AMBIGUITY!>foo<!><String, Int>()
c.foo<String, Int>()
}
}
@@ -10,6 +10,6 @@ interface B {
fun test(c: Any) {
if (c is B && c is A) {
c.<!AMBIGUITY!>foo<!>()
c.foo()
}
}
@@ -17,37 +17,37 @@ interface C {
fun foo(x: Any?) {
if (x is A && x is B) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
x.foo().checkType { _<String?>() }
}
if (x is B && x is A) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
x.foo().checkType { _<String?>() }
}
if (x is A && x is C) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { _<String>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String?>() }
}
if (x is C && x is A) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { _<String>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String?>() }
}
if (x is A && x is B && x is C) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { _<String>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String?>() }
}
if (x is B && x is A && x is C) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { _<String>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String?>() }
}
if (x is B && x is C && x is A) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
x.foo().checkType { _<String>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String?>() }
}
}
@@ -14,6 +14,6 @@ interface B : Common {
fun test(c: Common) {
if (c is B && c is A) {
c.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
c.foo().checkType { _<String>() }
}
}
@@ -10,6 +10,6 @@ interface B {
fun test(c: Any) {
if (c is B && c is A) {
c.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
c.foo().checkType { _<String>() }
}
}
@@ -13,9 +13,9 @@ interface B: A {
fun test(a: A) {
if (a is B && a is C) {
a.<!AMBIGUITY!>foo<!> = ""
a.<!AMBIGUITY!>foo<!> = null
a.foo = ""
a.foo = null
a.<!AMBIGUITY!>foo<!>.<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
a.foo.checkType { _<String>() }
}
}
@@ -13,8 +13,8 @@ interface B: A {
fun test(a: A) {
if (a is B && a is C) {
a.<!AMBIGUITY!>foo<!> = ""
a.<!AMBIGUITY!>foo<!> = null
a.<!AMBIGUITY!>foo<!>
a.foo = ""
a.foo = null
a.foo
}
}
@@ -28,11 +28,11 @@ fun test() {
x.foo().checkType { _<CharSequence?>() }
if (x is B && x is C) {
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><CharSequence?>() }
x.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence?>() }
x.baz("")
x.<!AMBIGUITY!>baz<!>(1).<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Unit>() }
x.<!AMBIGUITY!>baz<!>(1, 2)
x.baz(1).checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Unit>() }
x.baz(1, 2)
x.<!AMBIGUITY!>foobar<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
x.foobar().checkType { _<String>() }
}
}
@@ -10,6 +10,6 @@ interface B {
fun test(c: Any) {
if (c is B && c is A) {
c.<!AMBIGUITY!>foo<!><String, Int>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
c.foo<String, Int>().checkType { _<Int>() }
}
}