[NI] discriminate Nothing for reified parameters
Related issues: KT-32836, KT-35728
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE
|
||||
|
||||
interface Bound
|
||||
|
||||
fun <T : Bound> take(t: T?): T = t ?: TODO()
|
||||
inline fun <reified T : Bound> takeReified(t: T?): T = t ?: TODO()
|
||||
inline fun <reified T> takeReifiedUnbound(t: T?): T = t ?: TODO()
|
||||
|
||||
fun <M : Bound> materialize(): M = TODO()
|
||||
inline fun <reified M : Bound> materializeReified(): M = TODO()
|
||||
inline fun <reified M> materializeReifiedUnbound(): M = TODO()
|
||||
|
||||
fun <T> select(a: T, b: T): T = TODO()
|
||||
|
||||
fun test1() {
|
||||
take(null)
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
takeReified(null)
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
takeReifiedUnbound(null)
|
||||
}
|
||||
|
||||
fun test4(): Bound = takeReifiedUnbound(null)
|
||||
|
||||
fun test5(): Bound? = select(
|
||||
null,
|
||||
materialize()
|
||||
)
|
||||
|
||||
fun test6() {
|
||||
select(
|
||||
null,
|
||||
materializeReified()
|
||||
)
|
||||
}
|
||||
|
||||
fun test7(): Bound? =
|
||||
select(
|
||||
null,
|
||||
materializeReifiedUnbound()
|
||||
)
|
||||
|
||||
fun test8() {
|
||||
select(
|
||||
null,
|
||||
materializeReifiedUnbound()
|
||||
)
|
||||
}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE
|
||||
|
||||
interface Bound
|
||||
|
||||
fun <T : Bound> take(t: T?): T = t ?: TODO()
|
||||
inline fun <reified T : Bound> takeReified(t: T?): T = t ?: TODO()
|
||||
inline fun <reified T> takeReifiedUnbound(t: T?): T = t ?: TODO()
|
||||
|
||||
fun <M : Bound> materialize(): M = TODO()
|
||||
inline fun <reified M : Bound> materializeReified(): M = TODO()
|
||||
inline fun <reified M> materializeReifiedUnbound(): M = TODO()
|
||||
|
||||
fun <T> select(a: T, b: T): T = TODO()
|
||||
|
||||
fun test1() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!><!IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>take<!>(null)<!>
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Bound")!>takeReified(null)<!>
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>takeReifiedUnbound<!>(null)
|
||||
}
|
||||
|
||||
fun test4(): Bound = <!DEBUG_INFO_EXPRESSION_TYPE("Bound")!>takeReifiedUnbound(null)<!>
|
||||
|
||||
fun test5(): Bound? = select(
|
||||
null,
|
||||
<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, IMPLICIT_NOTHING_AS_TYPE_PARAMETER!>materialize<!>()
|
||||
)
|
||||
|
||||
fun test6() {
|
||||
select(
|
||||
null,
|
||||
<!IMPLICIT_NOTHING_AS_TYPE_PARAMETER, IMPLICIT_NOTHING_AS_TYPE_PARAMETER, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>materializeReified<!>()
|
||||
)
|
||||
}
|
||||
|
||||
fun test7(): Bound? =
|
||||
select(
|
||||
null,
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Bound?")!>materializeReifiedUnbound()<!>
|
||||
)
|
||||
|
||||
fun test8() {
|
||||
select(
|
||||
null,
|
||||
<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>materializeReifiedUnbound<!>()
|
||||
)
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/nothingType/discriminateNothingForReifiedParameter.txt
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ M : Bound> materialize(): M
|
||||
public inline fun </*0*/ reified M : Bound> materializeReified(): M
|
||||
public inline fun </*0*/ reified M> materializeReifiedUnbound(): M
|
||||
public fun </*0*/ T> select(/*0*/ a: T, /*1*/ b: T): T
|
||||
public fun </*0*/ T : Bound> take(/*0*/ t: T?): T
|
||||
public inline fun </*0*/ reified T : Bound> takeReified(/*0*/ t: T?): T
|
||||
public inline fun </*0*/ reified T> takeReifiedUnbound(/*0*/ t: T?): T
|
||||
public fun test1(): kotlin.Unit
|
||||
public fun test2(): kotlin.Unit
|
||||
public fun test3(): kotlin.Unit
|
||||
public fun test4(): Bound
|
||||
public fun test5(): Bound?
|
||||
public fun test6(): kotlin.Unit
|
||||
public fun test7(): Bound?
|
||||
public fun test8(): kotlin.Unit
|
||||
|
||||
public interface Bound {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
interface ExpectedType
|
||||
|
||||
inline fun <reified M> parse(): M? = TODO()
|
||||
|
||||
fun test(s: String?, silent: Boolean) {
|
||||
val result: ExpectedType =
|
||||
if (s != null) {
|
||||
parse() ?: TODO()
|
||||
} else if (silent) {
|
||||
return
|
||||
} else {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
s.<!INAPPLICABLE_CANDIDATE!>length<!>
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
interface ExpectedType
|
||||
|
||||
inline fun <reified M> parse(): M? = TODO()
|
||||
|
||||
fun test(s: String?, silent: Boolean) {
|
||||
val result: ExpectedType =
|
||||
if (s != null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ExpectedType?")!>parse()<!> ?: TODO()
|
||||
} else <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>if (silent) {
|
||||
return
|
||||
} else {
|
||||
throw Exception()
|
||||
}<!>
|
||||
|
||||
<!DEBUG_INFO_SMARTCAST!>s<!>.length
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ reified M> parse(): M?
|
||||
public fun test(/*0*/ s: kotlin.String?, /*1*/ silent: kotlin.Boolean): kotlin.Unit
|
||||
|
||||
public interface ExpectedType {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
inline fun <reified T> parse(json: String): T? = TODO()
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
inline fun <reified T> parse(json: String): T? = TODO()
|
||||
|
||||
@@ -7,7 +6,7 @@ class MyType
|
||||
|
||||
fun parseMyData(json: String): MyType =
|
||||
try {
|
||||
<!NI;REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, NI;REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>parse<!>(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter
|
||||
parse(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter
|
||||
?: throw IllegalArgumentException("Can't parse")
|
||||
} catch (e: Exception) {
|
||||
throw IllegalArgumentException("Can't parse")
|
||||
|
||||
Reference in New Issue
Block a user