Avoid non-null assertions for inline classes based on nullable types

Note that there are more places where assertions for inline classes should refined:
  - lateinit vars
  - values that come from Java
  - type casts (interfaces to inline class type)
This commit is contained in:
Mikhail Zarechenskiy
2018-02-20 12:46:14 +03:00
parent e3c58eced1
commit f23b5103ec
11 changed files with 115 additions and 15 deletions

View File

@@ -0,0 +1,14 @@
// !LANGUAGE: +InlineClasses
inline class AsNonNullPrimitive(val i: Int)
inline class AsNonNullReference(val s: String) // 2 assertions (constructor, box method)
fun nonNullPrimitive(a: AsNonNullPrimitive) {}
fun nonNullReference(b: AsNonNullReference) {} // assertion
fun AsNonNullReference.nonNullReferenceExtension(b1: AsNonNullReference) {} // 2 assertions
fun asNullablePrimitive(c: AsNonNullPrimitive?) {}
fun asNullableReference(c: AsNonNullReference?) {}
// 5 checkParameterIsNotNull

View File

@@ -0,0 +1,8 @@
// !LANGUAGE: +InlineClasses
inline class AsAny(val a: Any?)
fun asNotNullAny(a: AsAny) {}
fun AsAny.asNotNullAnyExtension(b: AsAny): AsAny = this
// 0 checkParameterIsNotNull