[Issue 12578] Allow local function overloading
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 15 03:01:01 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12578
--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Walter Bright from comment #3)
> 2. Forward references aren't allowed in local scope, meaning any use of
> overloading would be fairly restricted anyway.
By adding following rule for function local declarations, we can relax the
restriction.
- If no runtime statements exist between two local declarations,
compiler will declare them in one DeclDef scope.
Examples:
----
void main() {
//{
void foo()
void foo(int) {}
// These are declared in one DeclDef scope, so they can be overloaded each
other.
//}
}
The rule will work on general case.
void main() {
struct S {
int foo() { bar(); }
static assert(x == 10);
}
void bar() { S s; }
enum x = 10;
// Declaraing S, bar, and x have no runtime side effect,
// so they can be referred to each other.
}
If same name function declarations are divided to multiple DeclDefs, they
cannot be overloaded.
void main() {
void foo()
void foo(int) {}
// foo == overloaded function
// --> ok
int x; // runtime statement divides DeclDefs
void foo(string) {}
// Another declaration of foo will conflict with the overloaded foo.
// --> error
}
--
More information about the Digitalmars-d-bugs
mailing list