Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function templates conflict with aliases #17635

Open
dlangBugzillaToGithub opened this issue Jan 5, 2014 · 1 comment
Open

function templates conflict with aliases #17635

dlangBugzillaToGithub opened this issue Jan 5, 2014 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

monarchdodra reported this on 2014-01-05T13:34:13Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=11873

Description

Apparently, this is according to spec, but I think it should be legal.

Simple functions? No problem:
//----
void foo();
void bar(int);

alias foo = bar;

void main()
{
    foo();
    foo(5);
}
//----

Templates? Problem:
//----
void foo()(); //Template here
void bar(int);

alias foo = bar;

void main()
{
    foo();
    foo(5);
}
//----
main.d(4): Error: alias main.foo conflicts with template main.foo()() at main.d(1)
//----

I think there should not be such a conflict. There is no reason for the alias not to work.

The above code is trivial, but a real world scenario where this can happen, is when a module wants to publicly import a named template function overload:

A.d
//----
module a;
foo(int); //Special "int" overload 
//----

B.d
//----
module b;
foo()(); //Standard 0-arg signature;
public import A : foo; //re-use "int"
//----

Because of this,
@dlangBugzillaToGithub
Copy link
Author

monarchdodra commented on 2014-01-05T13:37:52Z

(In reply to comment #0)
> Templates? Problem:
> //----
> void foo()(); //Template here
> void bar(int);
> 
> alias foo = bar;
> 
> void main()
> {
>     foo();
>     foo(5);
> }
> //----
> main.d(4): Error: alias main.foo conflicts with template main.foo()() at
> main.d(1)
> //----
> 
> I think there should not be such a conflict. There is no reason for the alias
> not to work.

Just to be clear, I think this should be legal, as there is absolutly no conflict between the original symbol, and the alias anyways.

Perfectly legal:
//----
void foo()();
void foo(int);

void main()
{
    foo();
    foo(5);
}
//----

If that works, why does the alias create a conflict?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant