modelbuilder: extra-warn useless type declaration of attributes
authorJean Privat <jean@pryen.org>
Tue, 12 Nov 2013 05:38:08 +0000 (00:38 -0500)
committerJean Privat <jean@pryen.org>
Tue, 12 Nov 2013 05:38:08 +0000 (00:38 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelize_property.nit

index 2f94421..ec035be 100644 (file)
@@ -687,8 +687,8 @@ redef class AAttrPropdef
                        if mtype == null then return
                end
 
+               var nexpr = self.n_expr
                if mtype == null then
-                       var nexpr = self.n_expr
                        if nexpr != null then
                                if nexpr isa ANewExpr then
                                        mtype = modelbuilder.resolve_mtype(nclassdef, nexpr.n_type)
@@ -717,6 +717,14 @@ redef class AAttrPropdef
                        else
                                modelbuilder.error(self, "Error: Untyped attribute {mpropdef}")
                        end
+               else
+                       assert ntype != null
+                       if nexpr isa ANewExpr then
+                               var xmtype = modelbuilder.resolve_mtype(nclassdef, nexpr.n_type)
+                               if xmtype == mtype and modelbuilder.toolcontext.opt_warn.value >= 2 then
+                                       modelbuilder.warning(ntype, "Warning: useless type definition")
+                               end
+                       end
                end
 
                if mtype == null then return