if sup == sub then
self.modelbuilder.warning(node, "Warning: Expression is already a {sup}.")
- else if self.is_subtype(sub, sup) and not sup.need_anchor then
+ else if self.is_subtype(sub, sup) then
self.modelbuilder.warning(node, "Warning: Expression is already a {sup} since it is a {sub}.")
end
return sup
assert mproperty isa MMethod
- if is_toplevel_context and recv_is_self and not mproperty.is_toplevel and name != "sys" and name != "exit" and name != "args" then
+ if is_toplevel_context and recv_is_self and not mproperty.is_toplevel and name != "sys" and name != "exit" then
# FIXME named methods are here as a workaround
error(node, "Error: '{name}' is not a top-level method, thus need a receiver.")
end
if mclass == null then return # Forward error
self.mtype = mclass.mclass_type
for nexpr in self.n_exprs do
- var t = v.visit_expr(nexpr)
+ v.visit_expr_subtype(nexpr, v.mmodule.object_type)
end
end
end
redef fun accept_typing(v)
do
var mtype = v.visit_expr(self.n_expr)
+ if mtype == null then return # Forward error
+
if mtype isa MNullType then
v.error(self, "Type error: as(not null) on null")
return
self.mtype = mtype.mtype
return
end
- # TODO: warn on useless as not null
self.mtype = mtype
+
+ if mtype isa MClassType then
+ v.modelbuilder.warning(self, "Warning: expression is already not null, since it is a `{mtype}`.")
+ return
+ end
+ assert mtype.need_anchor
+ var u = v.anchor_to(mtype)
+ if not u isa MNullableType then
+ v.modelbuilder.warning(self, "Warning: expression is already not null, since it is a `{mtype}: {u}`.")
+ return
+ end
end
end