Bug 144 – Alias and function names fail to collide

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2006-05-17T19:10:39Z
Last change time
2017-11-01T15:47:29Z
Keywords
accepts-invalid, bootcamp
Assigned to
No Owner
Creator
BCS

Comments

Comment #0 by shro8822 — 2006-05-17T19:10:39Z
When a function and an alias have the same name, DMD fails to produce an error unless the function is used directly. Taking the address off the name give no error. In the following test case the function (not the alias) is arbitrarily picked, however it is also the first definition and if this follows the pattern set in bug #52, reversing the order of the definitions will change this (not checked). Test case: ------------- void fn(){assert(0);} // make a function void gm(){assert(0);} // make another function alias gm fn; // alias the second with the name of the first void main() { // make pointer-to-function from name void function() fnp = & fn; // call pointer-to-function fnp(); // fn(); // wont compile with this line included } -------------
Comment #1 by thomas-dloop — 2006-05-19T11:46:44Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-05-18: > When a function and an alias have the same name, DMD fails to produce an error > unless the function is used directly. Taking the address off the name give no > error. > > In the following test case the function (not the alias) is arbitrarily picked, > however it is also the first definition and if this follows the pattern set in > bug #52, reversing the order of the definitions will change this (not checked). Added to DStress as http://dstress.kuehne.cn/nocompile/a/alias_35_A.d http://dstress.kuehne.cn/nocompile/a/alias_35_B.d http://dstress.kuehne.cn/nocompile/a/alias_35_C.d http://dstress.kuehne.cn/nocompile/a/alias_35_D.d http://dstress.kuehne.cn/nocompile/a/alias_35_E.d http://dstress.kuehne.cn/nocompile/a/alias_35_F.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEbcjD3w+/yD4P9tIRAn+JAJ4nA+Q/c4pQkhSoY5+masDI8sYHCwCgkROO nJgMRGSwQ9zzFPElpY8GC+k= =Zv6L -----END PGP SIGNATURE-----
Comment #2 by michal.minich — 2010-12-09T04:55:24Z
The bug still exists in DMD 2.050 fnp allays points to function fn; order has no effect.
Comment #3 by edmccard — 2012-07-13T13:23:26Z
There is an order dependency: void gm(){assert(0);} alias gm fn; void fn(){assert(0);} and fnp points to gm, but void gm(){assert(0);} void fn(){assert(0);} alias gm fn; and then fnp points to fn.
Comment #4 by razvan.nitu1305 — 2017-11-01T15:47:29Z
This is not a bug, it's the desired behavior since alias is used to include functions in the same overload set. It can't issue an error when an alias has the same name as a function, otherwise it would be impossible to bring other functions to the overload set. For example: if you have 3 foo overloads: void foo() {} void foo(int a) {} void foo(int a, int b) {} and you want to bring an imported function in the same overload set you do: alias foo = path.to.import.foo The problem in your example is that the 2 functions you bring in the same overload set have the exact same signature and are in the same file. So the compiler let's alias your function because it thinks you want to have the in the same overload set, but when you try to call it, it issues an error because it does not know which one it should call. This is correct behavior. Closing as invalid.