X-Git-Url: http://nitlanguage.org diff --git a/src/typing.nit b/src/typing.nit index 5db0ada..a415667 100644 --- a/src/typing.nit +++ b/src/typing.nit @@ -191,7 +191,7 @@ private class TypeVisitor 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 @@ -252,8 +252,7 @@ private class TypeVisitor 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 - # FIXME named methods are here as a workaround + if is_toplevel_context and recv_is_self and not mproperty.is_toplevel then error(node, "Error: '{name}' is not a top-level method, thus need a receiver.") end if not recv_is_self and mproperty.is_toplevel then @@ -278,13 +277,13 @@ private class TypeVisitor end - var msignature = mpropdef.msignature.as(not null) + var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null) msignature = resolve_for(msignature, recvtype, recv_is_self).as(MSignature) var erasure_cast = false var rettype = mpropdef.msignature.return_mtype if not recv_is_self and rettype != null then - if rettype isa MNullableType then rettype = rettype.mtype + rettype = rettype.as_notnullable if rettype isa MParameterType then var erased_rettype = msignature.return_mtype assert erased_rettype != null @@ -905,7 +904,7 @@ redef class AForExpr # anchor formal and virtual types if mtype.need_anchor then mtype = v.anchor_to(mtype) - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable self.coltype = mtype.as(MClassType) # get methods is_ok, next, item @@ -1008,9 +1007,7 @@ redef class AOrElseExpr return # Skip error end - if t1 isa MNullableType then - t1 = t1.mtype - end + t1 = t1.as_notnullable var t = v.merge_types(self, [t1, t2]) if t == null then @@ -1081,7 +1078,7 @@ redef class ASuperstringExpr 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 @@ -1194,6 +1191,8 @@ redef class AAsNotnullExpr 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 @@ -1202,8 +1201,18 @@ redef class AAsNotnullExpr 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 @@ -1258,6 +1267,9 @@ redef class ASendExpr if not (vmpropdef isa MMethodDef and vmpropdef.mproperty.is_init) then v.error(self, "Can call a init only in another init") end + if vmpropdef isa MMethodDef and vmpropdef.mproperty.is_root_init and not callsite.mproperty.is_root_init then + v.error(self, "Error: {vmpropdef} cannot call a factory {callsite.mproperty}") + end end var ret = msignature.return_mtype @@ -1513,12 +1525,15 @@ redef class ASuperExpr if v.modelbuilder.toolcontext.error_count > errcount then return # Forard error continue # Try next super-class end - if superprop != null and superprop.mproperty != candidate then + if superprop != null and candidate.is_root_init then + continue + end + if superprop != null and superprop.mproperty != candidate and not superprop.mproperty.is_root_init then v.error(self, "Error: conflicting super constructor to call for {mproperty}: {candidate.full_name}, {superprop.mproperty.full_name}") return end var candidatedefs = candidate.lookup_definitions(v.mmodule, recvtype) - if superprop != null then + if superprop != null and superprop.mproperty == candidate then if superprop == candidatedefs.first then continue candidatedefs.add(superprop) end @@ -1533,7 +1548,7 @@ redef class ASuperExpr return end - var msignature = superprop.msignature.as(not null) + var msignature = superprop.new_msignature or else superprop.msignature.as(not null) msignature = v.resolve_for(msignature, recvtype, true).as(MSignature) var callsite = new CallSite(self, recvtype, v.mmodule, v.anchor, true, superprop.mproperty, superprop, msignature, false)