Prevent early deleting of not-null assertions
Before val to var conversion applied, smart-cast can cause dropping not-null assertion, which will be required when val will become var
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class A {
|
||||
|
||||
/* rare nullable, handle with caution */
|
||||
public String nullableString() {
|
||||
if (Math.random() > 0.999) {
|
||||
return "a string";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void takesNotNullString(@NotNull String s) {
|
||||
System.out.println(s.substring(1));
|
||||
}
|
||||
|
||||
public void aVoid() {
|
||||
String aString;
|
||||
if (nullableString() != null) {
|
||||
aString = nullableString();
|
||||
if (aString != null) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
takesNotNullString(aString); // Bang-bang here
|
||||
aString = nullableString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
aString = "aaa";
|
||||
}
|
||||
}
|
||||
else {
|
||||
aString = "bbbb";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user