D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11873 - function templates conflict with aliases
Summary: function templates conflict with aliases
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-05 13:34 UTC by monarchdodra
Modified: 2024-12-13 18:15 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description monarchdodra 2014-01-05 13:34:13 UTC
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,
Comment 1 monarchdodra 2014-01-05 13:37:52 UTC
(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?
Comment 2 dlangBugzillaToGithub 2024-12-13 18:15:39 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17635

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB