typing: remove most top-level things
authorJean Privat <jean@pryen.org>
Wed, 8 Apr 2015 13:51:31 +0000 (20:51 +0700)
committerJean Privat <jean@pryen.org>
Fri, 10 Apr 2015 10:31:53 +0000 (17:31 +0700)
only kept for `new` factories and `sys` (for the moment)

Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/global_compiler.nit
src/modelize/modelize_property.nit
src/semantize/typing.nit

index 1aff84e..ede1beb 100644 (file)
@@ -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
 
index c224b29..d4a5654 100644 (file)
@@ -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
index ce51fa3..940f67e 100644 (file)
@@ -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