[Issue 14161] UFCS call does not abide by scope
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Feb 10 07:40:30 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14161
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bearophile_hugs at eml.cc
--- Comment #7 from bearophile_hugs at eml.cc ---
(In reply to Ketmar Dark from comment #6)
> here compiler should issue warning that "global 'f' chosen for UFCS instead
> of local one". yes, this is by spec, but sometimes people forgetting about
> this and expecting local call.
This code prints "foo2" without warnings and errors:
import std.stdio;
void foo() { writeln("foo1"); }
void main() {
void foo() { writeln("foo2"); }
foo();
}
while this gives a shadowing error message:
struct Foo { int x; }
void main() {
int x;
Foo f;
with (f)
x++;
}
test.d(6): Error: with symbol test.Foo.x is shadowing local symbol test.main.x
In theory this looks like the first case, where a local function (pointer)
silently shadows a module-level function:
import std.stdio;
void foo(int a) {
writeln("it's a function! : ", a);
}
void main() {
auto foo = (int a) { writeln("It's a variable! : ", a); };
5.foo();
foo(5);
}
But this behaviour looks a little surprising. So perhaps in this case specifc
it's better to give a shadowing error (with a warning/deprecation phase first),
to avoid ambiguity. Like with() when no actual ambiguity is present in the
code, no error message should be generated.
--
More information about the Digitalmars-d-bugs
mailing list