1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package regtest.basic;
void f_iS(?int x, ?String y) {}
void test_null()
{
?List<String> l = null;
//f_iS(null, null);
try{
notNull(null)(null);
}
catch(NullPointerException e){
println("OK");
}
catch(AssertionFailed e){
println("OK");
}
f();
}
// Testing the coverage test
<T1, T2 | T1 <: ?String , T2 <: T1> void cov(T1 s1, T2 s2);
// The domain of cov is exactly (?String, ?String)
// Therefore there are exactly four cases:
cov(s1@String, s2@String) {}
cov(s1@String, null) {}
cov(null, s2@String) {}
cov(null, null) {}
// nullness marker with a parameterized type in constraint
<T | T <: ?List<String>> void cov2(T x) {}
// Test inference of non-nullness
?String double1(?String s)
{
if (s == null)
return null;
return s + s;
}
?String double2(?String s) = s == null ? null : s + s;
?String double3(?String s) = s != null ? s + s : null;
// nullness test occuring inside an overloaded function
String double4(?String s) = "A" + (s != null ? s + s : null);
// nullness test occuring inside an overloaded constructor
String double5(?String s) = new String(s != null ? s + s : null);
void f()
{
?int x = 1;
?float f = x;
while (x != null)
{
x++;
x = null;
}
if (x != null)
x++;
else
return;
x++;
}
class NullClass
{
?String possiblyNull = null;
}
NullClass nullClass() = new NullClass();
|