typing: Add `do_typing` on AExpr
[nit.git] / src / semantize / typing.nit
index 3176e35..7c530c1 100644 (file)
@@ -325,7 +325,12 @@ private class TypeVisitor
 
                if mproperty == null then
                        if recv_is_self then
-                               self.modelbuilder.error(node, "Error: method or variable `{name}` unknown in `{recvtype}`.")
+                               # FIXME This test was added to display a more explicit error when a potential duplication of root object class.
+                               if name == "init" then
+                                       self.modelbuilder.error(node, "Possible duplication of the root class `Object`")
+                               else
+                                       self.modelbuilder.error(node, "Error: method or variable `{name}` unknown in `{recvtype}`.")
+                               end
                        else if recvtype.need_anchor then
                                self.modelbuilder.error(node, "Error: method `{name}` does not exists in `{recvtype}: {unsafe_type}`.")
                        else
@@ -1027,6 +1032,18 @@ redef class AExpr
                end
                return res
        end
+
+       # Type the expression as if located in `visited_mpropdef`
+       # `TypeVisitor` and `PostTypingVisitor` will be used to do the typing, see them for more information.
+       #
+       # `visited_mpropdef`: Correspond to the evaluation context in which the expression is located.
+       fun do_typing(modelbuilder: ModelBuilder, visited_mpropdef: MPropDef)
+       do
+               var type_visitor = new TypeVisitor(modelbuilder, visited_mpropdef)
+               type_visitor.visit_stmt(self)
+               var post_visitor = new PostTypingVisitor(type_visitor)
+               post_visitor.enter_visit(self)
+       end
 end
 
 redef class ABlockExpr