X-Git-Url: http://nitlanguage.org diff --git a/src/typing.nit b/src/typing.nit index abf1597..719fae2 100644 --- a/src/typing.nit +++ b/src/typing.nit @@ -501,12 +501,6 @@ redef class AConcreteMethPropdef assert variable != null variable.declared_type = mtype end - for i in [0..mmethoddef.msignature.mclosures.length[ do - var mclosure = mmethoddef.msignature.mclosures[i] - var variable = self.n_signature.n_closure_decls[i].variable - assert variable != null - variable.declared_type = mclosure.mtype - end v.visit_stmt(nblock) if not nblock.after_flow_context.is_unreachable and mmethoddef.msignature.return_mtype != null then @@ -646,9 +640,6 @@ redef class AVarAssignExpr end redef class AReassignFormExpr - # @depreciated use `reassign_callsite` - fun reassign_property: nullable MMethodDef do return self.reassign_callsite.mpropdef - # The method designed by the reassign operator. var reassign_callsite: nullable CallSite @@ -702,6 +693,8 @@ redef class AVarReassignExpr var readtype = v.get_variable(self, variable) if readtype == null then return + read_type = readtype + var writetype = variable.declared_type if writetype == null then return @@ -894,6 +887,10 @@ redef class AForExpr v.error(self, "Type Error: Expected method 'iterator' to return an Iterator of MapIterator type") return end + + # anchor formal and virtual types + if mtype.need_anchor then mtype = v.anchor_to(mtype) + self.coltype = mtype.as(MClassType) # get methods is_ok, next, item @@ -1002,21 +999,16 @@ redef class AOrElseExpr var t = v.merge_types(self, [t1, t2]) if t == null then - v.error(self, "Type Error: ambiguous type {t1} vs {t2}") + t = v.mmodule.object_type + if t2 isa MNullableType then + t = t.as_nullable + end + #v.error(self, "Type Error: ambiguous type {t1} vs {t2}") end self.mtype = t end end -redef class AEeExpr - redef fun accept_typing(v) - do - v.visit_expr(n_expr) - v.visit_expr(n_expr2) - self.mtype = v.type_bool(self) - end -end - redef class ATrueExpr redef fun accept_typing(v) do @@ -1195,9 +1187,6 @@ end ## MESSAGE SENDING AND PROPERTY redef class ASendExpr - # @depreciated: use `callsite` - fun mproperty: nullable MMethod do return callsite.mproperty - # The property invoked by the send. var callsite: nullable CallSite @@ -1235,14 +1224,6 @@ redef class ASendExpr else self.is_typed = true end - - if self.n_closure_defs.length == msignature.mclosures.length then - for i in [0..self.n_closure_defs.length[ do - self.n_closure_defs[i].accept_typing(v, msignature.mclosures[i]) - end - else - debug("closure: got {self.n_closure_defs.length}, want {msignature.mclosures.length}") - end end # The name of the property @@ -1366,9 +1347,6 @@ redef class ABraAssignExpr end redef class ASendReassignFormExpr - # @depreciated use `write_callsite` - fun write_mproperty: nullable MMethod do return write_callsite.mproperty - # The property invoked for the writing var write_callsite: nullable CallSite @@ -1439,7 +1417,7 @@ end redef class ASuperExpr # The method to call if the super is in fact a 'super init call' # Note: if the super is a normal call-next-method, then this attribute is null - var mproperty: nullable MMethod + var callsite: nullable CallSite redef fun accept_typing(v) do @@ -1460,7 +1438,6 @@ redef class ASuperExpr end # FIXME: covariance of return type in linear extension? var superprop = superprops.first - assert superprop isa MMethodDef var msignature = v.resolve_signature_for(superprop, recvtype, true) var args = self.n_args.to_a @@ -1504,12 +1481,14 @@ redef class ASuperExpr v.error(self, "Error: No super method to call for {mproperty}.") return end - self.mproperty = superprop.mproperty - var args = self.n_args.to_a var msignature = v.resolve_signature_for(superprop, recvtype, true) + var callsite = new CallSite(self, recvtype, true, superprop.mproperty, superprop, msignature, false) + self.callsite = callsite + + var args = self.n_args.to_a if args.length > 0 then - v.check_signature(self, args, mproperty.name, msignature) + callsite.check_signature(v, args) else # TODO: Check signature end @@ -1521,9 +1500,6 @@ end #### redef class ANewExpr - # @depreciated use `callsite` - fun mproperty: nullable MMethod do return self.callsite.mproperty - # The constructor invoked by the new. var callsite: nullable CallSite @@ -1541,6 +1517,14 @@ redef class ANewExpr v.error(self, "Type error: cannot instantiate the formal type {recvtype}.") return end + else + if recvtype.mclass.kind == abstract_kind then + v.error(self, "Cannot instantiate abstract class {recvtype}.") + return + else if recvtype.mclass.kind == interface_kind then + v.error(self, "Cannot instantiate interface {recvtype}.") + return + end end var name: String @@ -1654,50 +1638,6 @@ end ### -redef class AClosureCallExpr - redef fun accept_typing(v) - do - var variable = self.variable - if variable == null then return # Skip error - - var recvtype = v.nclassdef.mclassdef.bound_mtype - var msignature = variable.declared_type.as(not null) - msignature = v.resolve_for(msignature, recvtype, false).as(MSignature) - - var args = n_args.to_a - v.check_signature(self, args, variable.name, msignature) - - self.is_typed = true - self.mtype = msignature.return_mtype - end -end - -redef class AClosureDef - var mclosure: nullable MParameter - - private fun accept_typing(v: TypeVisitor, mparameter: MParameter) - do - var variables = self.variables - if variables == null then return - - self.mclosure = mparameter - var msignature = mparameter.mtype.as(MSignature) - - if msignature.arity != variables.length then - v.error(self, "Type error: closure {mparameter.name} expects {msignature.arity} parameters, {variables.length} given") - return - end - - for i in [0..variables.length[ do - variables[i].declared_type = msignature.mparameters[i].mtype - end - - v.visit_stmt(self.n_expr) - end -end - -### - redef class ADebugTypeExpr redef fun accept_typing(v) do