fixes bugs in TypeInfo

This commit is contained in:
Alex Tkachman
2011-09-01 14:01:05 +02:00
parent 9e9959f953
commit 475b15aaca
4 changed files with 96 additions and 18 deletions
@@ -1740,7 +1740,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
v.dup();
}
Type type = typeMapper.boxType(typeMapper.mapType(jetType, OwnerKind.INTERFACE));
v.instanceOf(type);
if(jetType.isNullable()) {
Label nope = new Label();
Label end = new Label();
v.dup();
v.ifnull(nope);
v.instanceOf(type);
v.goTo(end);
v.mark(nope);
v.pop();
v.aconst(1);
v.mark(end);
}
else {
v.instanceOf(type);
}
}
}
@@ -11,6 +11,7 @@ import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
@@ -1708,7 +1709,7 @@ public class JetTypeInferrer {
return;
}
if (TypeUtils.intersect(semanticServices.getTypeChecker(), Sets.newHashSet(type, subjectType)) == null) {
context.trace.getErrorHandler().genericError(reportErrorOn.getNode(), "Incompatible types: " + type + " and " + subjectType); // TODO : message
context.trace.getErrorHandler().genericError(reportErrorOn.getNode(), "Incompatible types: " + type + " and " + subjectType + " " + ErrorHandler.atLocation(reportErrorOn));
}
}
+52 -6
View File
@@ -1,20 +1,66 @@
class A() {}
class B<T>() {}
class B<T>() {
fun isT (a : Any?) : Boolean {
return a is T
}
}
fun box() : String {
fun t1() : Boolean {
val a = A()
System.out?.println(a is A) //true
System.out?.println(a is A?) //true
if(a !is A) return false
if(a !is A?) return false
if(null !is A?) return false
return true
}
fun t2 () : Boolean {
val b = B<String>()
System.out?.println(b is B<String>) //true
System.out?.println(b is B<String>?) //false !!!
if(b !is B<String>) return false
if(b !is B<String>?) return false
if(null !is B<String>?) return false
val v = b as B<String> //ok
val u = b as B<String>? //TypeCastException
val w : B<String>? = b as B<String> //ok
val x = w as B<String>? //TypeCastException
return true
}
fun t3 () : Boolean {
val b = B<String>()
if(!b.isT("aaa")) return false
if(b.isT(10)) return false
if(b.isT(null)) return false
val d = B<String?>()
if(!d.isT("aaa")) return false
if(d.isT(10)) return false
if(!d.isT(null)) return false
val c = B<Int>()
if(c.isT("aaa")) return false
if(!c.isT(10)) return false
if(c.isT(null)) return false
val e = B<Int?>()
if(e.isT("aaa")) return false
if(!e.isT(10)) return false
if(!e.isT(null)) return false
return true
}
fun box() : String {
if(!t1()) {
return "t1 failed"
}
if(!t2()) {
return "t2 failed"
}
if(!t3()) {
return "t3 failed"
}
return "OK"
}