typing: warn `useless-type` for useless type in a local variable
authorJean Privat <jean@pryen.org>
Thu, 27 Nov 2014 20:30:01 +0000 (15:30 -0500)
committerJean Privat <jean@pryen.org>
Fri, 28 Nov 2014 01:04:35 +0000 (20:04 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/semantize/typing.nit

index 3140de5..cdb8ae8 100644 (file)
@@ -668,7 +668,11 @@ redef class AVardeclExpr
                var nexpr = self.n_expr
                if nexpr != null then
                        if mtype != null then
-                               v.visit_expr_subtype(nexpr, mtype)
+                               var etype = v.visit_expr_subtype(nexpr, mtype)
+                               if etype == mtype then
+                                       assert ntype != null
+                                       v.modelbuilder.advice(ntype, "useless-type", "Warning: useless type definition for variable `{variable.name}`")
+                               end
                        else
                                mtype = v.visit_expr(nexpr)
                                if mtype == null then return # Skip error