typing: allow `new` on interface and abstract classes that have a `new`-factory
authorJean Privat <jean@pryen.org>
Wed, 22 Oct 2014 19:03:46 +0000 (15:03 -0400)
committerJean Privat <jean@pryen.org>
Thu, 23 Oct 2014 17:02:32 +0000 (13:02 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/separate_compiler.nit
src/compiler/separate_erasure_compiler.nit
src/semantize/typing.nit

index 6797978..216ccd5 100644 (file)
@@ -98,7 +98,7 @@ redef class ModelBuilder
                compiler.do_property_coloring
                for m in mainmodule.in_importation.greaters do
                        for mclass in m.intro_mclasses do
-                               if mclass.kind == abstract_kind or mclass.kind == interface_kind then continue
+                               #if mclass.kind == abstract_kind or mclass.kind == interface_kind then continue
                                compiler.compile_class_to_c(mclass)
                        end
                end
index c23476d..55844f6 100644 (file)
@@ -226,7 +226,7 @@ class SeparateErasureCompiler
                var v = self.new_visitor
 
                var rta = runtime_type_analysis
-               var is_dead = mclass.kind == abstract_kind or mclass.kind == interface_kind
+               var is_dead = false # mclass.kind == abstract_kind or mclass.kind == interface_kind
                if not is_dead and rta != null and not rta.live_classes.has(mclass) and mtype.ctype == "val*" and mclass.name != "NativeArray" then
                        is_dead = true
                end
index 8c648a0..83bebc2 100644 (file)
@@ -1696,14 +1696,6 @@ 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
 
                self.recvtype = recvtype
@@ -1719,6 +1711,13 @@ redef class ANewExpr
                if callsite == null then return
 
                if not callsite.mproperty.is_new then
+                       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
                        self.mtype = recvtype
                else
                        self.mtype = callsite.msignature.return_mtype