Sign in Join

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

Mailing lists / lazarus / 2016-01

Code completion question

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt

Hi,

Just curious: if I ask code completion in a class

TMyClass = Class(TMYParentClass)
Protected
Procedure Valid|

Cursor is at |. I ask the codetools to complete in order to override a method in the parent class.
It doesn't show a procedure that it I KNOW is present in the parent class.

Then it dawned on me: the procedure exists, but is Public. I changed the visibility to public, and then I got the procedure.

So:
do the codetools refuse to show identifiers with less restricted visibility ? (so in a protected section, I will not get public)

Is this intentional ?

I can imagine it is confusing to the beginner and experienced dev alike...

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 7 lines
[...] do the codetools refuse to show identifiers with less restricted visibility ? (so in a protected section, I will not get public) Is this intentional ? I can imagine it is confusing to the beginner and experienced dev alike...

Please report the bug.

Mattias

Reply by email

Vojtěch Čihák
to Mattias Gaertner

Hi,
?
It is a bug? I know this behaviour for a long time and I always believed it is by design. ?
V.
______________________________________________________________

Show quoted text 5 lines
Od: Mattias Gaertner Komu: Datum: 26.01.2016 22:46 P?edm?t: Re: [Lazarus] Code completion question
Show quoted text 7 lines
[...] do the codetools refuse to show identifiers with less restricted visibility ? (so in a protected section, I will not get public) Is this intentional ? I can imagine it is confusing to the beginner and experienced dev alike...

Please report the bug.

Mattias

Reply by email

Mattias Gaertner
to Vojtěch Čihák
Hi, ? It is a bug? I know this behaviour for a long time and I always believed it is by design.

FPC gives a warning, so it is bad coding, but it is not forbidden.

Maybe it would be better to show them in the completion box with some warning marker.

Mattias

Reply by email

Ondrej Pokorny
to Vojtěch Čihák: ? It is a bug? I know this behaviour for a long time and I always believed it is by…
Vojt?ch ?ih?k wrote
It is a bug? I know this behaviour for a long time and I always believed it is by design.

I also came across it and it confused me for a second as well. Then I realized my mistake.

But anyway, you can do it and the code compiles, so CodeTools should allow it. During the compilation you get a hint about "overriden method has lower visibility [...]", if I remember correctly.

So yes, to avoid confusion I would say the visibility filter is unnecessarily restrictive.

+ What bugs me even more is that protected methods are not available with the inherited keyword:

procedure TMyClass2.Foo;
begin
   inherited Proc // CodeTools do not list Proc that is in protected
section of parent class from different unit. It works without the
"inherited" keyword, though
end;

I have to check why.

Ondrej

Reply by email

Ondrej Pokorny
to Ondrej Pokorny: I also came across it and it confused me for a second as well. Then I realized my mistake.
Ondrej Pokorny wrote 11 lines
+ What bugs me even more is that protected methods are not available with the inherited keyword: procedure TMyClass2.Foo; begin inherited Proc // CodeTools do not list Proc that is in protected section of parent class from different unit. It works without the "inherited" keyword, though end; I have to check why.

Fixed this one in r51425. Hopefully with no regressions.

Ondrej

Reply by email