var g = local_class.global
v.add_instr("if (({recv}!=NIT_NULL) && !VAL_ISA({recv}, {g.color_id}, {g.id_id})) \{ fprintf(stderr, \"Cast failled\"); {v.printf_locate_error(n)} nit_exit(1); } /*cast {self}*/;")
end
+
+ # Compile a notnull cast assertion
+ meth compile_notnull_check(v: CompilerVisitor, recv: String, n: PNode)
+ do
+ if is_nullable then
+ v.add_instr("if (({recv}==NIT_NULL)) \{ fprintf(stderr, \"Cast failled\"); {v.printf_locate_error(n)} nit_exit(1); } /*cast {self}*/;")
+ end
+ end
end
###############################################################################
end
end
+redef class AAsNotnullExpr
+ redef meth compile_expr(v)
+ do
+ var e = v.compile_expr(n_expr)
+ n_expr.stype.compile_notnull_check(v, e, self)
+ return e
+ end
+end
+
redef class ATrueExpr
redef meth compile_expr(v)
do