Browse Source

* take care of m_duplicate_names when checking for duplicate locals, resolves #33221

git-svn-id: trunk@44028 -
florian 5 years ago
parent
commit
d87a5cc9fb
3 changed files with 32 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/symtable.pas
  3. 30 0
      tests/webtbs/tw33221.pp

+ 1 - 0
.gitattributes

@@ -17801,6 +17801,7 @@ tests/webtbs/tw33167.pp svneol=native#text/pascal
 tests/webtbs/tw3320.pp svneol=native#text/plain
 tests/webtbs/tw3320.pp svneol=native#text/plain
 tests/webtbs/tw33202.pp svneol=native#text/pascal
 tests/webtbs/tw33202.pp svneol=native#text/pascal
 tests/webtbs/tw33205.pp -text svneol=native#text/plain
 tests/webtbs/tw33205.pp -text svneol=native#text/plain
+tests/webtbs/tw33221.pp svneol=native#text/pascal
 tests/webtbs/tw33222.pp svneol=native#text/pascal
 tests/webtbs/tw33222.pp svneol=native#text/pascal
 tests/webtbs/tw33230.pp svneol=native#text/pascal
 tests/webtbs/tw33230.pp svneol=native#text/pascal
 tests/webtbs/tw3324.pp svneol=native#text/plain
 tests/webtbs/tw3324.pp svneol=native#text/plain

+ 1 - 1
compiler/symtable.pas

@@ -2460,7 +2460,7 @@ implementation
            assigned(tprocdef(defowner).struct) and
            assigned(tprocdef(defowner).struct) and
            (tprocdef(defowner).owner.defowner=tprocdef(defowner).struct) and
            (tprocdef(defowner).owner.defowner=tprocdef(defowner).struct) and
            (
            (
-            not(m_delphi in current_settings.modeswitches) or
+            not(m_duplicate_names in current_settings.modeswitches) or
             is_object(tprocdef(defowner).struct)
             is_object(tprocdef(defowner).struct)
            ) then
            ) then
           result:=tprocdef(defowner).struct.symtable.checkduplicate(hashedid,sym);
           result:=tprocdef(defowner).struct.symtable.checkduplicate(hashedid,sym);

+ 30 - 0
tests/webtbs/tw33221.pp

@@ -0,0 +1,30 @@
+program Project1;
+ 
+{$mode objfpc}{$H+}
+{$ModeSwitch duplicatelocals}
+ 
+type
+  TClass1 = class(TObject)
+  public
+    X: Integer;
+    procedure Proc1(X: Integer);
+    procedure Proc2;
+  end;
+ 
+// Parameter has same name as member field.
+// This is okay with duplicatelocals
+procedure TClass1.Proc1(X: Integer);
+begin
+end;
+ 
+// Local variable has same name as member field.
+// Unlike with delphi mode, this is compiler error, even with duplicatelocals!
+procedure TClass1.Proc2;
+var
+  X: Integer;
+begin
+end;
+ 
+begin
+end.    
+