FIR: Consider abbreviation's nullability when expanding types

This commit is contained in:
Denis Zharkov
2020-02-10 16:43:42 +03:00
parent 2bb6e4fd97
commit 003aea2e68
7 changed files with 49 additions and 8 deletions
@@ -98,11 +98,17 @@ fun ConeClassLikeType.directExpansionType(
.toSymbol(useSiteSession)
?.safeAs<FirTypeAliasSymbol>()?.fir ?: return null
val resultType = expandedConeType(typeAlias) ?: return null
val resultType = expandedConeType(typeAlias)?.applyNullabilityFrom(this) ?: return null
if (resultType.typeArguments.isEmpty()) return resultType
return mapTypeAliasArguments(typeAlias, this, resultType) as? ConeClassLikeType
}
private fun ConeClassLikeType.applyNullabilityFrom(abbreviation: ConeClassLikeType): ConeClassLikeType {
if (abbreviation.isMarkedNullable) return withNullability(ConeNullability.NULLABLE)
return this
}
private fun mapTypeAliasArguments(
typeAlias: FirTypeAlias,
abbreviatedType: ConeClassLikeType,
@@ -0,0 +1,12 @@
// FULL_JDK
private typealias MyAlias = CharSequence
class A {
private val foo = java.util.concurrent.ConcurrentHashMap<String, MyAlias>()
private fun bar() {
foo["dd"]?.baz()
}
private fun MyAlias.baz() {}
}
@@ -0,0 +1,18 @@
FILE: concurrentMapOfAliases.kt
private final typealias MyAlias = R|kotlin/CharSequence|
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
private final val foo: R|java/util/concurrent/ConcurrentHashMap<kotlin/String, kotlin/CharSequence>| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|<R|kotlin/String|, R|kotlin/CharSequence|>()
private get(): R|java/util/concurrent/ConcurrentHashMap<kotlin/String, kotlin/CharSequence>|
private final fun bar(): R|kotlin/Unit| {
(this@R|/A|, this@R|/A|.R|/A.foo|.R|FakeOverride<java/util/concurrent/ConcurrentHashMap.get: R|kotlin/CharSequence?|>|(String(dd)))?.R|/A.baz|()
}
private final fun R|MyAlias|.baz(): R|kotlin/Unit| {
}
}
@@ -78,6 +78,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
runTest("compiler/fir/resolve/testData/resolve/stdlib/concurrent.kt");
}
@TestMetadata("concurrentMapOfAliases.kt")
public void testConcurrentMapOfAliases() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/stdlib/concurrentMapOfAliases.kt");
}
@TestMetadata("emptyArray.kt")
public void testEmptyArray() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/stdlib/emptyArray.kt");
@@ -13,8 +13,8 @@ public class Throwables() {
}
}
public fun propagateIfPossible(throwable : Throwable?) : Unit {
<!INAPPLICABLE_CANDIDATE!>propagateIfInstanceOf<!>(throwable, getJavaClass<Error?>()) // Type inference failed: Mismatch while expanding constraints
<!INAPPLICABLE_CANDIDATE!>propagateIfInstanceOf<!>(throwable, getJavaClass<RuntimeException?>()) // Type inference failed: Mismatch while expanding constraints
propagateIfInstanceOf(throwable, getJavaClass<Error?>()) // Type inference failed: Mismatch while expanding constraints
propagateIfInstanceOf(throwable, getJavaClass<RuntimeException?>()) // Type inference failed: Mismatch while expanding constraints
}
}
}
}
@@ -10,8 +10,8 @@ public class Throwables() {
}
}
public fun propagateIfPossible(throwable : Throwable?) {
<!INAPPLICABLE_CANDIDATE!>propagateIfInstanceOf<!>(throwable, getJavaClass<Error?>()) //; Type inference failed: Mismatch while expanding constraints
<!INAPPLICABLE_CANDIDATE!>propagateIfInstanceOf<!>(throwable, getJavaClass<RuntimeException?>()) // Type inference failed: Mismatch while expanding constraints
propagateIfInstanceOf(throwable, getJavaClass<Error?>()) //; Type inference failed: Mismatch while expanding constraints
propagateIfInstanceOf(throwable, getJavaClass<RuntimeException?>()) // Type inference failed: Mismatch while expanding constraints
}
}
}
}
@@ -9,4 +9,4 @@ val ms: MyString = "MyString"
val msn: MyString? = null
val msc: MyStringContainer = Container(ms)
val msc1 = <!INAPPLICABLE_CANDIDATE!>MyStringContainer<!>(null)
val msc1 = MyStringContainer(null)