typing: ANew distinguish the type of the class and the returned type
[nit.git] / src / astbuilder.nit
index 428a5ca..620bf49 100644 (file)
@@ -154,7 +154,7 @@ redef class AExpr
        # Note: this method, aimed to `ABlockExpr` is promoted to `AExpr` because of the limitations of the hierarchies generated by sablecc3
        fun add(expr: AExpr)
        do
-               print "add not inplemented in {inspect}"
+               print "add not implemented in {inspect}"
                abort
        end
 end
@@ -275,7 +275,12 @@ redef class ANewExpr
                        n_args.n_exprs.add_all(args)
                end
                self.callsite = callsite
-               self.mtype = callsite.recv
+               self.recvtype = callsite.recv.as(MClassType)
+               if callsite.mproperty.is_new then
+                       self.mtype = callsite.msignature.return_mtype
+               else
+                       self.mtype = callsite.recv
+               end
                self.is_typed = true
        end
 end
@@ -289,7 +294,6 @@ redef class ACallExpr
                if args != null then
                        self.n_args.n_exprs.add_all(args)
                end
-               var mtype = recv.mtype.as(not null)
                self.callsite = callsite
                self.mtype = callsite.msignature.return_mtype
                self.is_typed = true