Sign in Join

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

Mailing lists / lazarus / 2012-02

How well should Lazarus check method parameters?

15 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd

I've just spotted this in my code:

procedure FormCloseQuery(Sender: TObject; CanClose: boolean);
..
procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean);

Those were inserted by some old version of the IDE, presumably the current version inserts the missing var.

Shouldn't either the IDE or the runtimes pick up this error?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Mattias Gaertner
to Mark Morgan Lloyd
Show quoted text 8 lines
I've just spotted this in my code: procedure FormCloseQuery(Sender: TObject; CanClose: boolean); .. procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); Those were inserted by some old version of the IDE, presumably the current version inserts the missing var.

I don't remember such a bug, but I'm not sure. Maybe it was there for a very short time and you were just unlucky.

Shouldn't either the IDE or the runtimes pick up this error?

It's valid code. What do you expect?

Mattias

Mark Morgan Lloyd
to Mattias Gaertner
Mattias Gaertner wrote 14 lines
On Wed, 22 Feb 2012 20:55:01 +0000 Mark Morgan Lloyd wrote: > I've just spotted this in my code: > > procedure FormCloseQuery(Sender: TObject; CanClose: boolean); > .. > procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); > > Those were inserted by some old version of the IDE, presumably the > current version inserts the missing var. I don't remember such a bug, but I'm not sure. Maybe it was there for a very short time and you were just unlucky.

Only thing there is that I roughed that program out a long time before I was getting Lazarus from svn, so it might in fact be in one or more releases. Appears to be , so it's fairly unlikely that anybody's still using an affected copy.

> Shouldn't either the IDE or the runtimes pick up this error? It's valid code. What do you expect?

I'd expect the trunk IDE or runtimes to realise that the second parameter isn't compatible with the current definitions.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Sven Barth
to Mattias Gaertner: On Wed, 22 Feb 2012 20:55:01 +0000 I don't remember such a bug, but I'm not sure. Maybe…
"Mattias Gaertner" wrote 20 lines
On Wed, 22 Feb 2012 20:55:01 +0000 Mark Morgan Lloyd wrote: > I've just spotted this in my code: > > procedure FormCloseQuery(Sender: TObject; CanClose: boolean); > .. > procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); > > Those were inserted by some old version of the IDE, presumably the > current version inserts the missing var. I don't remember such a bug, but I'm not sure. Maybe it was there for a very short time and you were just unlucky. > Shouldn't either the IDE or the runtimes pick up this error? It's valid code. What do you expect?

Huh? And what will happen if this handler gets assigned to OnCloseQuery through the LFM?

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120223/9b287c6b/attachment-0001.html>

Mattias Gaertner
to Sven Barth
Show quoted text 24 lines
Am 22.02.2012 22:49 schrieb "Mattias Gaertner" : > > On Wed, 22 Feb 2012 20:55:01 +0000 > Mark Morgan Lloyd wrote: > > > I've just spotted this in my code: > > > > procedure FormCloseQuery(Sender: TObject; CanClose: boolean); > > .. > > procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); > > > > Those were inserted by some old version of the IDE, presumably the > > current version inserts the missing var. > > I don't remember such a bug, but I'm not sure. Maybe it was there for a > very short time and you were just unlucky. > > > > Shouldn't either the IDE or the runtimes pick up this error? > > It's valid code. What do you expect? Huh? And what will happen if this handler gets assigned to OnCloseQuery through the LFM?

The TReader can not find "procedure FormCloseQuery". It can only find methods in TListForm.

Mattias

Mattias Gaertner
to Mark Morgan Lloyd: Only thing there is that I roughed that program out a long time before I was getting…
Show quoted text 27 lines
Mattias Gaertner wrote: > On Wed, 22 Feb 2012 20:55:01 +0000 > Mark Morgan Lloyd wrote: > >> I've just spotted this in my code: >> >> procedure FormCloseQuery(Sender: TObject; CanClose: boolean); >> .. >> procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); >> >> Those were inserted by some old version of the IDE, presumably the >> current version inserts the missing var. > > I don't remember such a bug, but I'm not sure. Maybe it was there for a > very short time and you were just unlucky. Only thing there is that I roughed that program out a long time before I was getting Lazarus from svn, so it might in fact be in one or more releases. Appears to be , so it's fairly unlikely that anybody's still using an affected copy. >> Shouldn't either the IDE or the runtimes pick up this error? > > It's valid code. What do you expect? I'd expect the trunk IDE or runtimes to realise that the second parameter isn't compatible with the current definitions.

Ah, now I see what you mean:

TCloseQueryEvent = procedure(Sender : TObject; var CanClose : boolean) of object;

And you have

procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean);

Yes, the IDE adds the var when the event is created. I don't know when this was implemented - a long time ago.
There is currently no tool to fix the signatures.
The LFM / TReader does not check either.

You can create feature requests if you like.

Mattias

Mark Morgan Lloyd
to Mattias Gaertner: On Thu, 23 Feb 2012 09:54:52 +0100 The TReader can not find "procedure FormCloseQuery".…
Mattias Gaertner wrote 26 lines
On Thu, 23 Feb 2012 09:54:52 +0100 Sven Barth wrote: > Am 22.02.2012 22:49 schrieb "Mattias Gaertner" : >> On Wed, 22 Feb 2012 20:55:01 +0000 >> Mark Morgan Lloyd wrote: >> >>> I've just spotted this in my code: >>> >>> procedure FormCloseQuery(Sender: TObject; CanClose: boolean); >>> .. >>> procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); >>> >>> Those were inserted by some old version of the IDE, presumably the >>> current version inserts the missing var. >> I don't remember such a bug, but I'm not sure. Maybe it was there for a >> very short time and you were just unlucky. >> >> >>> Shouldn't either the IDE or the runtimes pick up this error? >> It's valid code. What do you expect? > Huh? And what will happen if this handler gets assigned to OnCloseQuery > through the LFM? The TReader can not find "procedure FormCloseQuery". It can only find methods in TListForm.

I might be missing something to my discredit, but this *is* in the TListForm:

type
   { TListForm }
   TListForm = class(TForm)
     Bevel1: TBevel;
     DialogFind: TFindDialog;
     DialogFont: TFontDialog;
     MenuItem1: TMenuItem;
..
     procedure FormCloseQuery(Sender: TObject; CanClose: boolean);
..
   public
     { public declarations }
     GlobalState: TGlobalState;
   end;
var
   ListForm: TListForm;

Comments in the code suggest that I was using whatever version was current in around '06 or possibly a bit older.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Mark Morgan Lloyd
to Mattias Gaertner: On Thu, 23 Feb 2012 07:07:47 +0000 Ah, now I see what you mean: TCloseQueryEvent =…
Mattias Gaertner wrote 37 lines
On Thu, 23 Feb 2012 07:07:47 +0000 Mark Morgan Lloyd wrote: > Mattias Gaertner wrote: >> On Wed, 22 Feb 2012 20:55:01 +0000 >> Mark Morgan Lloyd wrote: >> >>> I've just spotted this in my code: >>> >>> procedure FormCloseQuery(Sender: TObject; CanClose: boolean); >>> .. >>> procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); >>> >>> Those were inserted by some old version of the IDE, presumably the >>> current version inserts the missing var. >> I don't remember such a bug, but I'm not sure. Maybe it was there for a >> very short time and you were just unlucky. > Only thing there is that I roughed that program out a long time before I > was getting Lazarus from svn, so it might in fact be in one or more > releases. Appears to be , so it's fairly unlikely that > anybody's still using an affected copy. > >>> Shouldn't either the IDE or the runtimes pick up this error? >> It's valid code. What do you expect? > I'd expect the trunk IDE or runtimes to realise that the second > parameter isn't compatible with the current definitions. Ah, now I see what you mean: TCloseQueryEvent = procedure(Sender : TObject; var CanClose : boolean) of object; And you have procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); Yes, the IDE adds the var when the event is created. I don't know when this was implemented - a long time ago.

I suspect this code was originally roughed out in the middle of '06, I can see comments in there from August of that year.

There is currently no tool to fix the signatures. The LFM / TReader does not check either. You can create feature requests if you like.

I'll double-check the situation later with trunk and a trivial example and will file a report to get it into the record.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Mattias Gaertner
to Mark Morgan Lloyd: I might be missing something to my discredit, but this *is* in the TListForm: type {…
Mattias Gaertner wrote: [...] I might be missing something to my discredit, but this *is* in the TListForm:

Is this in the Lazarus sources?

Show quoted text 22 lines
type { TListForm } TListForm = class(TForm) Bevel1: TBevel; DialogFind: TFindDialog; DialogFont: TFontDialog; MenuItem1: TMenuItem; .. procedure FormCloseQuery(Sender: TObject; CanClose: boolean); .. public { public declarations } GlobalState: TGlobalState; end; var ListForm: TListForm; Comments in the code suggest that I was using whatever version was current in around '06 or possibly a bit older.

Mattias

Mark Morgan Lloyd
to Mattias Gaertner
Mattias Gaertner wrote 9 lines
On Thu, 23 Feb 2012 09:17:10 +0000 Mark Morgan Lloyd wrote: > Mattias Gaertner wrote: > [...] > I might be missing something to my discredit, but this *is* in the > TListForm: Is this in the Lazarus sources?

No, my own code but generated by the Lazarus IDE (circa 2006) and apparently still getting past current checks.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Flávio Etrusco
to Mark Morgan Lloyd: I've just spotted this in my code: procedure FormCloseQuery(Sender: TObject; CanClose:…
Mark Morgan Lloyd wrote
I've just spotted this in my code:

(...)

Show quoted text 10 lines
.. procedure TListForm.FormCloseQuery(Sender: TObject; CanClose: Boolean); Those were inserted by some old version of the IDE, presumably the current version inserts the missing var. Shouldn't either the IDE or the runtimes pick up this error? -- Mark Morgan Lloyd

I can't see any way to justify this not being catch by the compiler as an _error_. We should report it in the fpc-devel ML or in mantis.

Best regards,
Fl?vio

Vincent Snijders
to Flávio Etrusco

Op 24 februari 2012 13:13 heeft Fl?vio Etrusco
het volgende geschreven:

I can't see any way to justify this not being catch by the compiler as an _error_. We should report it in the fpc-devel ML or in mantis.

A compiler doesn't read the lfm file.

Vincent.

Flávio Etrusco
to Vincent Snijders
Vincent Snijders wrote 11 lines
Op 24 februari 2012 13:13 heeft Fl?vio Etrusco het volgende geschreven: > > I can't see any way to justify this not being catch by the compiler as > an _error_. We should report it in the fpc-devel ML or in mantis. A compiler doesn't read the lfm file. Vincent. --

Oops, I thought I tested it with code, not the designer (and now I see that test would've been meaningless anyway). I stand corrected. The current RTTI doesn't provide that much detail yet, then only the IDE can make that check, right?

-Fl?vio

Sven Barth
"Fl?vio Etrusco" wrote 19 lines
On Fri, Feb 24, 2012 at 10:42 AM, Vincent Snijders wrote: > Op 24 februari 2012 13:13 heeft Fl?vio Etrusco > het volgende geschreven: >> >> I can't see any way to justify this not being catch by the compiler as >> an _error_. We should report it in the fpc-devel ML or in mantis. > > A compiler doesn't read the lfm file. > > Vincent. > > -- Oops, I thought I tested it with code, not the designer (and now I see that test would've been meaningless anyway). I stand corrected. The current RTTI doesn't provide that much detail yet, then only the IDE can make that check, right?

Correct.

And AFAIK the object inspector already does not provide methods with incompatible declarations (though I don't know whether "var", "const" and "constref" are considered different). So in a current Lazarus you might not be able to achieve a situation like this, but it will not warn/fail if an older form contains such an event handler.

(My assumption is not completely verified, so handle wit care)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/7981cfea/attachment.html>

Mattias Gaertner
to Sven Barth
Show quoted text 26 lines
Am 24.02.2012 13:58 schrieb "Fl?vio Etrusco" : > > On Fri, Feb 24, 2012 at 10:42 AM, Vincent Snijders > wrote: > > Op 24 februari 2012 13:13 heeft Fl?vio Etrusco > > het volgende geschreven: > >> > >> I can't see any way to justify this not being catch by the compiler as > >> an _error_. We should report it in the fpc-devel ML or in mantis. > > > > A compiler doesn't read the lfm file. > > > > Vincent. > > > > -- > > Oops, I thought I tested it with code, not the designer (and now I see > that test would've been meaningless anyway). I stand corrected. > The current RTTI doesn't provide that much detail yet, then only the > IDE can make that check, right? Correct. And AFAIK the object inspector already does not provide methods with incompatible declarations (though I don't know whether "var", "const" and "constref" are considered different).

In general: yes.
It depends on the calling convention if you notice it.

Show quoted text 5 lines
So in a current Lazarus you might not be able to achieve a situation like this, but it will not warn/fail if an older form contains such an event handler. (My assumption is not completely verified, so handle wit care)

A check project/package dialog is needed to do various checks, including lfm files. But this has low priority to me.

Mattias