From: Jean Privat Date: Fri, 10 Apr 2015 05:16:03 +0000 (+0700) Subject: typing: `intern` is used to refer to the plain vanilla constructor X-Git-Tag: v0.7.4~27^2~1 X-Git-Url: http://nitlanguage.org typing: `intern` is used to refer to the plain vanilla constructor It is used to implement specific factories inside classes ~~~ class A new do var res = new A.intern res.do_things return res end end ~~~ Signed-off-by: Jean Privat --- diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index cf8bbda..93ed60d 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1809,6 +1809,7 @@ redef class ANewExpr end self.recvtype = recvtype + var kind = recvtype.mclass.kind var name: String var nid = self.n_id @@ -1817,11 +1818,24 @@ redef class ANewExpr else name = "new" end + if name == "intern" then + if kind != concrete_kind then + v.error(self, "Type Error: Cannot instantiate {kind} {recvtype}.") + return + end + if n_args.n_exprs.not_empty then + v.error(n_args, "Type Error: the intern constructor expects no arguments.") + return + end + # Our job is done + self.mtype = recvtype + return + end + var callsite = v.get_method(self, recvtype, name, false) if callsite == null then return if not callsite.mproperty.is_new then - var kind = recvtype.mclass.kind if kind != concrete_kind then v.error(self, "Type Error: Cannot instantiate {kind} {recvtype}.") return