Bug 4152 – Function alias forward reference error

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-05-03T04:33:47Z
Last change time
2024-12-13T17:52:18Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18226 →

Comments

Comment #0 by bearophile_hugs — 2010-05-03T04:33:47Z
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 by bearophile_hugs — 2010-08-22T13:26:09Z
Another case, maybe with a different cause: struct Foo(alias f) {} Foo!main baz; void main() {}
Comment #2 by b2.temp — 2024-11-25T15:53:04Z
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 by robert.schadek — 2024-12-13T17:52:18Z
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