D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4152 - Function alias forward reference error
Summary: Function alias forward reference error
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-05-03 04:33 UTC by bearophile_hugs
Modified: 2024-12-13 17:52 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-05-03 04:33:47 UTC
This compiles and runs with no errors with dmd 2.044:


int fun(TElem)(TElem[] arr) { return 10; }
alias fun!(char) alternative; // LINE A
int alternative(int[] arr) { return 20; } // LINE B
void caller(TOp)(TOp op, char[] s) {
    assert(op(s) == 10);
}
void main() {
    caller(&alternative, cast(char[])"abc");
}



But if I swap the line A and B:


int fun(TElem)(TElem[] arr) { return 10; }
int alternative(int[] arr) { return 20; } // LINE B
alias fun!(char) alternative; // LINE A
void caller(TOp)(TOp op, char[] s) {
    assert(op(s) == 10);
}
void main() {
    caller(&alternative, cast(char[])"abc");
}


Then dmd 2.044 shows:
test.d(5): Error: cannot implicitly convert expression (s) of type char[] to int[]
test.d(8): Error: template instance test.caller!(int function(int[] arr)) error instantiating
Comment 1 bearophile_hugs 2010-08-22 13:26:09 UTC
Another case, maybe with a different cause:


struct Foo(alias f) {}
Foo!main baz;
void main() {}
Comment 2 basile-z 2024-11-25 15:53:04 UTC
Wouldn't the bug be that in first place the "A then B" version works ?

It seems that the compiler silently selects the first overload member.

I think that AddrExp of an overload-set should not be allowed. This is like assuming that the following code should work:

```d
void f(char){}
void f(double){}

void main()
{
    auto badAddrOfOverSet = &f;
    f(0.0);
}   
```

and that is not the case.
Comment 3 dlangBugzillaToGithub 2024-12-13 17:52:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

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

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