From: Jean Privat Date: Wed, 8 Apr 2015 13:51:31 +0000 (+0700) Subject: typing: remove most top-level things X-Git-Tag: v0.7.4~31^2~4 X-Git-Url: http://nitlanguage.org?hp=b658b0e710e877b64fa4690017184ac498a3e2d4 typing: remove most top-level things only kept for `new` factories and `sys` (for the moment) Signed-off-by: Jean Privat --- diff --git a/src/compiler/global_compiler.nit b/src/compiler/global_compiler.nit index 1aff84e..ede1beb 100644 --- a/src/compiler/global_compiler.nit +++ b/src/compiler/global_compiler.nit @@ -528,11 +528,6 @@ class GlobalCompilerVisitor private fun get_recvtype(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): MClassType do check_valid_reciever(recvtype) - #debug("call {m} on {recvtype} on {args.first}:{args.first.mtype}") - if m.mproperty.is_toplevel then - # Do not customize top-level methods - recvtype = m.mclassdef.bound_mtype - end return recvtype end diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index c224b29..d4a5654 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -622,15 +622,6 @@ redef class APropdef modelbuilder.error(self, "Error: A property {mprop} is already defined in class {mclassdef.mclass} at line {mclassdef.mprop2npropdef[mprop].location.line_start}.") return false end - if mprop isa MMethod and mprop.is_toplevel != (parent isa ATopClassdef) then - if mprop.is_toplevel then - modelbuilder.error(self, "Error: {mprop} is a top level method.") - else - modelbuilder.error(self, "Error: {mprop} is not a top level method.") - end - return false - - end if mprop isa MMethod and mprop.is_root_init then return true if kwredef == null then if need_redef then @@ -824,7 +815,7 @@ redef class AMethPropdef mprop.is_init = is_init mprop.is_new = n_kwnew != null if mprop.is_new then mclassdef.mclass.has_new_factory = true - if parent isa ATopClassdef then mprop.is_toplevel = true + if name == "sys" then mprop.is_toplevel = true # special case for sys allowed in `new` factories self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop) else if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index ce51fa3..940f67e 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -52,6 +52,7 @@ private class TypeVisitor # Is `self` use restricted? # * no explicit `self` # * method called on the implicit self must be top-level + # Currently only used for `new` factory since there is no valid receiver inside var is_toplevel_context = false init @@ -71,7 +72,7 @@ private class TypeVisitor selfvariable.declared_type = mclass.mclass_type var mprop = mpropdef.mproperty - if mprop isa MMethod and (mprop.is_toplevel or mprop.is_new) then + if mprop isa MMethod and mprop.is_new then is_toplevel_context = true end end