[Lazarus] Wrong Duplicate Identifier error message?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Wrong Duplicate Identifier error message?

Free Pascal - Lazarus mailing list
Hi,

the following unit throws an (I think wrong) compile error "Duplicate
identifier 'Connection'". This happens Lazarus with 2.0.8 under Win 10 (64).
According to Nicklaus Wirth and Kathleen Jensen ('Pascal User Manual and
Report') there is no duplicate  identifier in this  unit, since
'Connection' in procedure Proc ist strictly local and does not interfere
with Identfiers outside this procedure.

Code:

unit DoubleDefinition;
{$mode objfpc}{$H+}
interface
  uses
   Classes, SysUtils, sqlite3conn, Forms, Controls, Graphics, Dialogs;
  type
    { TForm1 }
    TForm1 = class(TForm)
     Connection: TSQLite3Connection;
     procedure Proc;
   end;
var Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Proc;
var Connection: TSQLite3Connection;
begin
   Connection:=  TSQLite3Connection.Create(Form1);
   Connection.Free;
end;
end.

Regards --  Joe

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Wrong Duplicate Identifier error message?

Free Pascal - Lazarus mailing list
On Wed, 1 Jul 2020 20:15:45 +0200
Special via lazarus <[hidden email]> wrote:

>[...]
> the following unit throws an (I think wrong) compile error "Duplicate
> identifier 'Connection'". This happens Lazarus with 2.0.8 under Win
> 10 (64). According to Nicklaus Wirth and Kathleen Jensen ('Pascal
> User Manual and Report') there is no duplicate  identifier in this
> unit, since 'Connection' in procedure Proc ist strictly local and
> does not interfere with Identfiers outside this procedure.

You are aware, that this manual was way before Object Pascal?

 
> Code:
>
> unit DoubleDefinition;
> {$mode objfpc}{$H+}

$mode objfpc is more strict on duplicates.
FPC supports other modes like $mode Delphi, which allows this
duplicate.

Mattias
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Wrong Duplicate Identifier error message?

Free Pascal - Lazarus mailing list
Am 01.07.2020 um 20:36 schrieb Mattias Gaertner via lazarus:

> On Wed, 1 Jul 2020 20:15:45 +0200
> Special via lazarus <[hidden email]> wrote:
>
>> [...]
>> the following unit throws an (I think wrong) compile error "Duplicate
>> identifier 'Connection'". This happens Lazarus with 2.0.8 under Win
>> 10 (64). According to Nicklaus Wirth and Kathleen Jensen ('Pascal
>> User Manual and Report') there is no duplicate  identifier in this
>> unit, since 'Connection' in procedure Proc ist strictly local and
>> does not interfere with Identfiers outside this procedure.
> You are aware, that this manual was way before Object Pascal?
>
>  
>> Code:
>>
>> unit DoubleDefinition;
>> {$mode objfpc}{$H+}
> $mode objfpc is more strict on duplicates.
> FPC supports other modes like $mode Delphi, which allows this
> duplicate.
>
> Mattias

Here there is no Duplicate Identifier error message:

program Duplicate;
{$mode objfpc}{$H+}

var TestVar: string;

procedure Proc;
var TestVar: string;
begin
   TestVar:= 'zwei';
   writeln (TestVar)
end;

begin
   TestVar:= 'eins';
   writeln (TestVar);
   Proc
end.

Why this inconsistency?

Regards --  Joe

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Wrong Duplicate Identifier error message?

Free Pascal - Lazarus mailing list


On Thu, 2 Jul 2020, Special via lazarus wrote:

> Am 01.07.2020 um 20:36 schrieb Mattias Gaertner via lazarus:
>> On Wed, 1 Jul 2020 20:15:45 +0200
>> Special via lazarus <[hidden email]> wrote:
>>
>>> [...]
>>> the following unit throws an (I think wrong) compile error "Duplicate
>>> identifier 'Connection'". This happens Lazarus with 2.0.8 under Win
>>> 10 (64). According to Nicklaus Wirth and Kathleen Jensen ('Pascal
>>> User Manual and Report') there is no duplicate  identifier in this
>>> unit, since 'Connection' in procedure Proc ist strictly local and
>>> does not interfere with Identfiers outside this procedure.
>> You are aware, that this manual was way before Object Pascal?
>>
>>
>>> Code:
>>>
>>> unit DoubleDefinition;
>>> {$mode objfpc}{$H+}
>> $mode objfpc is more strict on duplicates.
>> FPC supports other modes like $mode Delphi, which allows this
>> duplicate.
>>
>> Mattias
>
> Here there is no Duplicate Identifier error message:
>
> program Duplicate;
> {$mode objfpc}{$H+}
>
> var TestVar: string;
>
> procedure Proc;
> var TestVar: string;
> begin
>   TestVar:= 'zwei';
>   writeln (TestVar)
> end;
>
> begin
>   TestVar:= 'eins';
>   writeln (TestVar);
>   Proc
> end.
>
> Why this inconsistency?
There is no inconsistency: there is no object.

An object in some way represents a single scope of identifiers.
In that sense, it makes sense to forbid duplicates. It's a thin line.

In practice, I find that the objfpc mode is less error prone
than the Delphi mode. I had some nasty surprises in the past in
Delphi with duplicate names in methods and properties.

Michael.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Wrong Duplicate Identifier error message?

Free Pascal - Lazarus mailing list
Am 02.07.2020 um 09:17 schrieb Michael Van Canneyt:
> An object in some way represents a single scope of identifiers. In
> that sense, it makes sense to forbid duplicates. It's a thin line.
>
> In practice, I find that the objfpc mode is less error prone than the
> Delphi mode. I had some nasty surprises in the past in
> Delphi with duplicate names in methods and properties.
>
> Michael.

Thanks for the clarification.
--  J o e



--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus