FIR Checker: check AMBIGUOUS_ANONYMOUS_TYPE_INFERRED

Also change
org.jetbrains.kotlin.fir.types.TypeUtilsKt#hideLocalTypeIfNeeded to skip
approximating anonymous objects if there are multiple super type refs so
that resolution behaves the same (for uncompilable code).

Note that this change does not implement check for
ApproximateAnonymousReturnTypesInPrivateInlineFunctions as the check is
already turned on in 1.5 and will likely not needed when FIR becomes
stable.
This commit is contained in:
Tianyu Geng
2021-09-01 13:30:02 -07:00
committed by teamcityserver
parent 6432388778
commit 76e192fc8a
14 changed files with 149 additions and 72 deletions
@@ -11,7 +11,7 @@ private inline fun foo2(crossinline f: () -> Int) = object : I1 {
fun bar(): Int = f()
}
private inline fun foo3(crossinline f: () -> Int) = object : I1, I2 {
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>private inline fun foo3(crossinline f: () -> Int)<!> = object : I1, I2 {
fun bar(): Int = f()
}
@@ -36,11 +36,11 @@ fun test2(b: Boolean) {
}
fun test3(b: Boolean) {
var x = <!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Cannot hide local type object : R|I1|, R|I2| { private constructor(): R|<anonymous>| { super<R|kotlin/Any|>() } public final fun bar(): R|kotlin/Int| { ^bar R|<local>/f|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Int|>|() }}")!>foo3 { 1 }<!>
var x = <!DEBUG_INFO_EXPRESSION_TYPE("<anonymous>")!>foo3 { 1 }<!>
if (b) {
x = <!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Cannot hide local type object : R|I1|, R|I2| { private constructor(): R|<anonymous>| { super<R|kotlin/Any|>() } public final fun bar(): R|kotlin/Int| { ^bar R|<local>/f|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Int|>|() }}")!>foo3 { 2 }<!>
x = <!DEBUG_INFO_EXPRESSION_TYPE("<anonymous>")!>foo3 { 2 }<!>
}
x.<!UNRESOLVED_REFERENCE!>bar<!>()
x.bar()
}
fun test4(b: Boolean) {
@@ -11,7 +11,7 @@ private inline fun foo2(crossinline f: () -> Int) = object : I1 {
fun bar(): Int = f()
}
private inline fun foo3(crossinline f: () -> Int) = object : I1, I2 {
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>private inline fun foo3(crossinline f: () -> Int)<!> = object : I1, I2 {
fun bar(): Int = f()
}
@@ -36,11 +36,11 @@ fun test2(b: Boolean) {
}
fun test3(b: Boolean) {
var x = <!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Cannot hide local type object : R|I1|, R|I2| { private constructor(): R|<anonymous>| { super<R|kotlin/Any|>() } public final fun bar(): R|kotlin/Int| { ^bar R|<local>/f|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Int|>|() }}")!>foo3 { 1 }<!>
var x = <!DEBUG_INFO_EXPRESSION_TYPE("<anonymous>")!>foo3 { 1 }<!>
if (b) {
x = <!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Cannot hide local type object : R|I1|, R|I2| { private constructor(): R|<anonymous>| { super<R|kotlin/Any|>() } public final fun bar(): R|kotlin/Int| { ^bar R|<local>/f|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Int|>|() }}")!>foo3 { 2 }<!>
x = <!DEBUG_INFO_EXPRESSION_TYPE("<anonymous>")!>foo3 { 2 }<!>
}
x.<!UNRESOLVED_REFERENCE!>bar<!>()
x.bar()
}
fun test4(b: Boolean) {