mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 05:28:07 +02:00
Merge branch 'dup' into 'main'
Allow DuplicateLocals for objects. See merge request freepascal.org/fpc/source!739
This commit is contained in:
commit
a7838b8ebf
@ -2522,7 +2522,8 @@ implementation
|
||||
(tprocdef(defowner).owner.defowner=tprocdef(defowner).struct) and
|
||||
(
|
||||
not(m_duplicate_names in current_settings.modeswitches) or
|
||||
is_object(tprocdef(defowner).struct)
|
||||
{ Delphi allows duplicates in classes/records but disallows in objects. }
|
||||
(m_delphi in current_settings.modeswitches) and is_object(tprocdef(defowner).struct)
|
||||
) then
|
||||
result:=tprocdef(defowner).struct.symtable.checkduplicate(hashedid,sym);
|
||||
end;
|
||||
|
@ -2,6 +2,7 @@ program Project1;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$ModeSwitch duplicatelocals}
|
||||
{$ModeSwitch advancedrecords}
|
||||
|
||||
type
|
||||
TClass1 = class(TObject)
|
||||
@ -18,13 +19,50 @@ begin
|
||||
end;
|
||||
|
||||
// Local variable has same name as member field.
|
||||
// Unlike with delphi mode, this is compiler error, even with duplicatelocals!
|
||||
// This is okay with duplicatelocals, too.
|
||||
procedure TClass1.Proc2;
|
||||
var
|
||||
X: Integer;
|
||||
begin
|
||||
end;
|
||||
|
||||
// Same for objects and managed records. (Though in Delphi mode, which implicitly enables duplicatelocals, disallowed specifically for objects.)
|
||||
type
|
||||
TRecord1 = record
|
||||
public
|
||||
X: Integer;
|
||||
procedure Proc1(X: Integer);
|
||||
procedure Proc2;
|
||||
end;
|
||||
|
||||
procedure TRecord1.Proc1(X: Integer);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TRecord1.Proc2;
|
||||
var
|
||||
X: Integer;
|
||||
begin
|
||||
end;
|
||||
|
||||
type
|
||||
TObject1 = object
|
||||
public
|
||||
X: Integer;
|
||||
procedure Proc1(X: Integer);
|
||||
procedure Proc2;
|
||||
end;
|
||||
|
||||
procedure TObject1.Proc1(X: Integer);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TObject1.Proc2;
|
||||
var
|
||||
X: Integer;
|
||||
begin
|
||||
end;
|
||||
|
||||
begin
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user