J2K: Insert !! for expression only if NotNull expected (not for Default nullability)
This commit is contained in:
@@ -96,7 +96,7 @@ class CodeConverter(
|
||||
|
||||
var convertedExpression = convertExpression(expression)
|
||||
|
||||
if (convertedExpression.isNullable && expectedNullability != null && !expectedNullability.isNullable(settings)) {
|
||||
if (convertedExpression.isNullable && expectedNullability != null && expectedNullability == Nullability.NotNull) {
|
||||
convertedExpression = BangBangExpression.surroundIfNullable(convertedExpression)
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,3 +1,5 @@
|
||||
// ERROR: Type mismatch: inferred type is Passenger.PassChild? but Passenger.PassChild was expected
|
||||
// ERROR: Type mismatch: inferred type is Passenger.PassChild? but Passenger.PassChild was expected
|
||||
class Passenger {
|
||||
open class PassParent
|
||||
|
||||
@@ -16,9 +18,9 @@ class Passenger {
|
||||
val pass = provideNullable(1)
|
||||
if (1 == 2) {
|
||||
assert(pass != null)
|
||||
accept2((pass as PassChild?)!!)
|
||||
accept2(pass as PassChild?)
|
||||
}
|
||||
accept2((pass as PassChild?)!!)
|
||||
accept2(pass as PassChild?)
|
||||
}
|
||||
|
||||
fun accept1(p: PassChild) {
|
||||
|
||||
+6
-2
@@ -1,3 +1,7 @@
|
||||
// ERROR: Type mismatch: inferred type is String? but String was expected
|
||||
// ERROR: Type mismatch: inferred type is Int? but Int was expected
|
||||
// ERROR: Type inference failed. Please try to specify type arguments explicitly.
|
||||
// ERROR: Using 'remove(Int): T' is an error. Use removeAt(index) instead.
|
||||
package test
|
||||
|
||||
import java.util.ArrayList
|
||||
@@ -16,7 +20,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
foo2(myProp!!)
|
||||
foo2(myProp)
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
@@ -39,7 +43,7 @@ class Test {
|
||||
|
||||
fun test7() {
|
||||
val list = ArrayList<Int>()
|
||||
list.remove(myIntProp!!)
|
||||
list.remove(myIntProp)
|
||||
}
|
||||
|
||||
fun foo1(s: String) {
|
||||
|
||||
Reference in New Issue
Block a user