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:
Simon Ogorodnik
2017-05-29 15:24:23 +03:00
parent e41c027c9a
commit a6e153312c
5 changed files with 89 additions and 5 deletions
@@ -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";
}
}
}