Name lookups in D
Steven Schveighoffer
schveiguy at gmail.com
Mon Dec 14 16:21:56 UTC 2020
On 12/13/20 4:54 PM, kdevel wrote:
> On Friday, 11 December 2020 at 01:38:44 UTC, Adam D. Ruppe wrote:
>
> [...]
>
>> With a normal import, the module name is the only thing actually added
>> to the scope. Everything in that module is found by walking the import
>> chains after not finding it locally (unless you use `static import`
>> which means it does not add it to the chain).
>
> Just 'implemented' the following bug:
>
> ~~~
> import std.conv;
>
> class B {
> }
>
> class D : B {
> string text;
> }
>
> void main ()
> {
> B b = new D;
> string s = b.text;
> }
> ~~~
>
> Due to UFCS std.conv.text grabs the object. Only a `static import`
> or a selective import would reveal the problem during compile time.
This is expected behavior. B does not have a member named "text", and so
it looks for a UFCS function to call and finds one.
Note that a static import means you have to use the FQN to call text
(but text is perfectly fine via UFCS). However, a selective import would
still call text as expected.
-Steve
More information about the Digitalmars-d
mailing list