From 7c2b37d4e9ab7e66840764cca0bce885886d6831 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 17 Dec 2014 11:45:42 -0500 Subject: [PATCH] typing: add `AArrayExpr::element_mtype` Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 2 +- src/semantize/typing.nit | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 5b88c2e..4c7987e 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -2650,7 +2650,7 @@ end redef class AArrayExpr redef fun expr(v) do - var mtype = self.mtype.as(MClassType).arguments.first + var mtype = self.element_mtype.as(not null) var array = new Array[RuntimeVariable] for nexpr in self.n_exprs do var i = v.expr(nexpr, mtype) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 4955eda..accfe11 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1180,9 +1180,15 @@ redef class ASuperstringExpr end redef class AArrayExpr + # The `with_capacity` method on Array var with_capacity_callsite: nullable CallSite + + # The `push` method on arrays var push_callsite: nullable CallSite + # The element of each type + var element_mtype: nullable MType + redef fun accept_typing(v) do var mtype: nullable MType = null @@ -1216,6 +1222,9 @@ redef class AArrayExpr assert ntype != null v.modelbuilder.warning(ntype, "useless-type", "Warning: useless type declaration `{mtype}` in literal Array since it can be inferred from the elements type.") end + + self.element_mtype = mtype + var mclass = v.get_mclass(self, "Array") if mclass == null then return # Forward error var array_mtype = mclass.get_mtype([mtype]) -- 1.7.9.5