typing: add `AArrayExpr::element_mtype`
authorJean Privat <jean@pryen.org>
Wed, 17 Dec 2014 16:45:42 +0000 (11:45 -0500)
committerJean Privat <jean@pryen.org>
Wed, 17 Dec 2014 20:29:27 +0000 (15:29 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit
src/semantize/typing.nit

index 5b88c2e..4c7987e 100644 (file)
@@ -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)
index 4955eda..accfe11 100644 (file)
@@ -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])