From f4d434e58088940f5a3e0a8c8f316f302e52be18 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 22 Oct 2014 15:03:46 -0400 Subject: [PATCH] typing: allow `new` on interface and abstract classes that have a `new`-factory Signed-off-by: Jean Privat --- src/compiler/separate_compiler.nit | 2 +- src/compiler/separate_erasure_compiler.nit | 2 +- src/semantize/typing.nit | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index 6797978..216ccd5 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -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 diff --git a/src/compiler/separate_erasure_compiler.nit b/src/compiler/separate_erasure_compiler.nit index c23476d..55844f6 100644 --- a/src/compiler/separate_erasure_compiler.nit +++ b/src/compiler/separate_erasure_compiler.nit @@ -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 diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 8c648a0..83bebc2 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -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 -- 1.7.9.5