]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not warn on assignment to same variable of different instance
authorJürg Billeter <j@bitron.ch>
Sat, 20 Mar 2010 15:50:18 +0000 (16:50 +0100)
committerJürg Billeter <j@bitron.ch>
Sat, 20 Mar 2010 15:50:18 +0000 (16:50 +0100)
vala/valaassignment.vala

index 38fda74de334cc676c3aea9313b8bd5eeda93c10..212685c988eed9f68dff3177ac42ee82e326960f 100644 (file)
@@ -358,9 +358,22 @@ public class Vala.Assignment : Expression {
                        }
 
                        var right_ma = right as MemberAccess;
-                       if (right_ma != null && ma.symbol_reference == right_ma.symbol_reference &&
-                           (ma.symbol_reference is LocalVariable || ma.symbol_reference is Field || ma.symbol_reference is FormalParameter)) {
-                               Report.warning (source_reference, "Assignment to same variable");
+                       if (right_ma != null && ma.symbol_reference == right_ma.symbol_reference) {
+                               if (ma.symbol_reference is LocalVariable || ma.symbol_reference is FormalParameter) {
+                                       Report.warning (source_reference, "Assignment to same variable");
+                               } else if (ma.symbol_reference is Field) {
+                                       var f = (Field) ma.symbol_reference;
+                                       if (f.binding == MemberBinding.STATIC) {
+                                               Report.warning (source_reference, "Assignment to same variable");
+                                       } else {
+                                               var ma_inner = ma.inner as MemberAccess;
+                                               var right_ma_inner = right_ma.inner as MemberAccess;
+                                               if (ma_inner != null && ma_inner.member_name == "this" && ma_inner.inner == null &&
+                                                   right_ma_inner != null && right_ma_inner.member_name == "this" && right_ma_inner.inner == null) {
+                                                       Report.warning (source_reference, "Assignment to same variable");
+                                               }
+                                       }
+                               }
                        }
                } else if (left is ElementAccess) {
                        var ea = (ElementAccess) left;