Files
kotlin-fork/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.kt
T
Dmitriy Novozhilov e6b5cb5216 [TD] Update diagnostics test data due to new test runners
Update includes:
- Changing syntax of `OI/`NI` tags from `<!NI;TAG!>` to `<!TAG{NI}!>`
- Fix some incorrect directives
- Change order of diagnostics in some places
- Remove ignored diagnostics from FIR test data (previously `DIAGNOSTICS` didn't work)
- Update FIR dumps in some places and add `FIR_IDENTICAL` if needed
- Replace all JAVAC_SKIP with SKIP_JAVAC directive
2020-12-16 19:52:25 +03:00

40 lines
1.2 KiB
Kotlin
Vendored

// !WITH_NEW_INFERENCE
// !CHECK_TYPE
fun main() {
val a : Int? = null
val b : Int? = null
checkSubtype<Int>(a!!)
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> + 2
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(2)
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(b!!)
2.plus(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
2 + b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
val c = 1
c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
val d : Any? = null
if (d != null) {
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// smart cast isn't needed, but is reported due to KT-4294
if (d is String) {
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (d is String?) {
if (d != null) {
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (d is String) {
<!DEBUG_INFO_SMARTCAST!>d<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
}
val <!UNUSED_VARIABLE!>f<!> : String = <!TYPE_MISMATCH!>a<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
checkSubtype<String>(<!TYPE_MISMATCH{NI}!><!TYPE_MISMATCH{OI}!>a<!><!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>)
}