mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-12 00:21:32 +00:00
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:
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user