Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2014-02

incompatibility change to default param in trunk?

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

Below works with 2.6.2 but not with trunk

Is that indented?

the wiki says

Show quoted text 15 lines
Default values are now properly typechecked * *Old behaviour*: The compiler did not detect default values for parameters of which the type did not in any way correspond to the parameter type. * *New behaviour*: The compiler now properly checks whether the type of the constant matches the parameter's type when parsing default values. * *Reason*: Proper type checking is one of the fundamental properties of the Pascal language; Delphi compatibility. * *Remedy*: Add a typecast around default values that now result in compiler errors, or correct the type of such parameters.

"did not in any way correspond to the parameter type" it does through the overloaded operator, doesn't it?

Also "add a typecast" (despite that would mean the overloaded operator isn't called),
the following

    procedure Test(a:TObject=TObject(1));

gives

   project1.lpr(6,36) Error: Illegal expression

even though 1 can be typecasted into an TObject.

program project1;
operator := (a:integer) b: TObject;
begin
   b:= TObject.Create;
end;
procedure Test(a:TObject=1);
begin
end;
begin
Test;
end.
Martin Frb
to Martin Frb

PING

Martin Frb wrote
Below works with 2.6.2 but not with trunk Is that indented?

Surely someone knows, if that is intended?

Show quoted text 43 lines
the wiki says > > > Default values are now properly typechecked > > * *Old behaviour*: The compiler did not detect default values for > parameters of which the type did not in any way correspond to the > parameter type. > * *New behaviour*: The compiler now properly checks whether the > type of the constant matches the parameter's type when parsing > default values. > * *Reason*: Proper type checking is one of the fundamental > properties of the Pascal language; Delphi compatibility. > * *Remedy*: Add a typecast around default values that now result in > compiler errors, or correct the type of such parameters. > "did not in any way correspond to the parameter type" it does through the overloaded operator, doesn't it? Also "add a typecast" (despite that would mean the overloaded operator isn't called), the following procedure Test(a:TObject=TObject(1)); gives project1.lpr(6,36) Error: Illegal expression even though 1 can be typecasted into an TObject. program project1; operator := (a:integer) b: TObject; begin b:= TObject.Create; end; procedure Test(a:TObject=1); begin end; begin Test; end.
Sven Barth
to Martin Frb
Martin Frb wrote 8 lines
PING On 08/02/2014 19:38, Martin Frb wrote: > Below works with 2.6.2 but not with trunk > > Is that indented? Surely someone knows, if that is intended?

Jonas is currently on vacation and he's the one who implemented it. You could try to crosstest with Delphi to see whether we are missing something.

Regards,
Sven

Martin Frb
to Sven Barth
Sven Barth wrote
Jonas is currently on vacation and he's the one who implemented it. You could try to crosstest with Delphi to see whether we are missing something.

I only have Turbo Delphi, and that does not seem to have operator overloading at all.

Sven Barth
to Martin Frb
Martin Frb wrote 7 lines
On 13/02/2014 07:40, Sven Barth wrote: > Jonas is currently on vacation and he's the one who implemented it. > You could try to crosstest with Delphi to see whether we are missing > something. I only have Turbo Delphi, and that does not seem to have operator 've looked at your example again. I would say it is by design that this

does not work (anymore) as the value of the default parameter is considered to be a constant expression. You can't use operator overloads either in const sections.

Regards,
Sven