Sign in Join

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

Mailing lists / fpc-devel / 2011-09

Issue 20124: Error with static "direct field" properties

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Alexander Klenin

[Is there any method to either comment on or re-open resolved isses? It is very frustrating to be forced to switch comminication channel]

I think this issue is resolved prematurely.
First, I do not see a reason why normal property can not be implemented by static field.
Second, even is such a reason is provided, compiler should error out instead of generating bogus code
(Optimal solution would be to issue a warning or hint and generate correct code).
Either way, "no change required" is IMHO wrong resolution.

Alexander S. Klenin

Reply by email

Florian Klaempfl
to Alexander Klenin
Alexander Klenin wrote 12 lines
[Is there any method to either comment on or re-open resolved isses? It is very frustrating to be forced to switch comminication channel] I think this issue is resolved prematurely. First, I do not see a reason why normal property can not be implemented by static field. Second, even is such a reason is provided, compiler should error out instead of generating bogus code (Optimal solution would be to issue a warning or hint and generate correct code). Either way, "no change required" is IMHO wrong resolution.

Maybe you should reread Jonas' comment? Apparently something in trunk has been changed regarding this already.

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote
Am 01.09.2011 17:48, schrieb Alexander Klenin: > [Is there any method to either comment on or re-open resolved isses? > It is very frustrating to be forced to switch comminication channel]

Only the submitter and people with "developer" access (or above) can do that, afaik.

Show quoted text 11 lines
> I think this issue is resolved prematurely. > First, I do not see a reason why normal property can not be > implemented by static field. > Second, even is such a reason is provided, compiler should error out > instead of generating bogus code > (Optimal solution would be to issue a warning or hint and generate > correct code). > Either way, "no change required" is IMHO wrong resolution. Maybe you should reread Jonas' comment? Apparently something in trunk has been changed regarding this already.

Trunk indeed gives an error if you don't use a class property:

Free Pascal Compiler version 2.7.1 [2011/08/18] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Darwin for i386
Compiling tt.pp
tt.pp(2,2) Warning: Illegal compiler directive "$STATIC" tt.pp(23,50) Error: Illegal symbol for property access tt.pp(24,48) Error: Illegal symbol for property access tt.pp(60) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

Jonas

Reply by email

Alexander Klenin
to Florian Klaempfl: Maybe you should reread Jonas' comment? Apparently something in trunk has been changed…
Florian Klaempfl wrote 11 lines
Am 01.09.2011 17:48, schrieb Alexander Klenin: > First, I do not see a reason why normal property can not be > implemented by static field. > Second, even is such a reason is provided, compiler should error out > instead of generating bogus code > (Optimal solution would be to issue a warning or hint and generate > correct code). > Either way, "no change required" is IMHO wrong resolution. Maybe you should reread Jonas' comment? Apparently something in trunk has been changed regarding this already.

Jonas' comment is:

static/class fields can only be read by class properties. Those are not yet supported by FPC 2.4.4, but they are in svn trunk.

I did not deduct from this that the error is now issued instead of wrong code. Testing indicates that it is indeed the case (the error message could be somewhat more descriptive,
but no big deal), so sorry for that.
This leaves the first point, however. Why is it prohibited at all?

Alexander S. Klenin

Reply by email

Alexander Klenin
to Jonas Maebe
Jonas Maebe wrote 7 lines
On 01 Sep 2011, at 18:42, Alexander Klenin wrote: > This leaves the first point, however. Why is it prohibited at all? I think because class properties have several limitations that normal properties do not have: http://docwiki.embarcadero.com/RADStudio/en/Properties#Class_Properties

That is quite understandable. The question is why FPC limits *normal* properties by disallowing them to be implemented via static fields?

Alexander S. Klenin

Reply by email

Jonas Maebe
to Alexander Klenin
Alexander Klenin wrote 10 lines
On Fri, Sep 2, 2011 at 03:50, Jonas Maebe wrote: > > On 01 Sep 2011, at 18:42, Alexander Klenin wrote: > >> This leaves the first point, however. Why is it prohibited at all? > > I think because class properties have several limitations that normal properties do not have: http://docwiki.embarcadero.com/RADStudio/en/Properties#Class_Properties That is quite understandable. The question is why FPC limits *normal* properties by disallowing them to be implemented via static fields?

Because those limitations of class properties stem from the fact that those things (stored, default value, published) don't make sense in combination with class methods/fields. It would of course be possible to add special checking code to make sure that they are not used with regular properties if either the setter or the getter maps to a static class methods/fields (that's another thing: a property that mixes & matches like that should probably also be forbidden, so that's another special case that would have to be checked), but overall I think the current way is much cleaner and easier to implement/maintain. And it's Delphi-compatible to boot.

Jonas

Reply by email