Thread overview
Strange error message with alias
Oct 20, 2006
Roberto Mariottini
Oct 20, 2006
Karen Lanrap
Oct 20, 2006
Ary Manzana
Oct 20, 2006
Karen Lanrap
October 20, 2006
Hi,

===============================
alias int A;

void f(int x)
{
}

void f(A x)
{
}
===============================

Gives the following error message:

===============================
C:\Down\dlang>dmd test.d
C:\Down\dlang\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

test.obj(test)  Offset 000CDH Record Type 00C3
 Error 1: Previous Definition Different : _D8test1fFiZv
OPTLINK : Warning 23: No Stack
OPTLINK : Warning 134: No Start Address
--- errorlevel 1
===============================

IMHO the compiler should issue an error before the linker complains for a duplicated identifier. It is also difficult to find which symbol is duplicated.

Ciao
October 20, 2006
Roberto Mariottini wrote:

> C:\Down\dlang>dmd test.d

You do not have a main() but you are stating to the compiler that there is a main(). Not having a main() has to be denoted by the '-c' option, which make the message vanish.

If you would call one of the 'f' you would get a not so cryptic error message.

> _D8test1fFiZv
> It is also difficult to find which symbol is duplicated.

The mangled name shoukd read '_D4test1fFiZv'. May be you want to write your own little demangle tool.
October 20, 2006
Karen Lanrap wrote:
> Roberto Mariottini wrote:
> 
>> C:\Down\dlang>dmd test.d
> 
> You do not have a main() but you are stating to the compiler that there is a main(). Not having a main() has to be denoted by the '-c' option, which make the message vanish.
> 
> If you would call one of the 'f' you would get a not so cryptic error message. 
> 
>> _D8test1fFiZv
>> It is also difficult to find which symbol is duplicated.
> 
> The mangled name shoukd read '_D4test1fFiZv'. May be you want to write your own little demangle tool.

The problem he was referring to was of the "overloaded" function. The answer should be what it is said in http://www.digitalmars.com/d/declaration.html :

---
Aliased types are semantically identical to the types they are aliased to. The debugger (AND compiler) cannot distinguish between them, and there is no difference as far as function overloading is concerned. For example:

alias int myint;

void foo(int x) { . }
void foo(myint m) { . }	// error, multiply defined function foo
---

So the error is correct: you have defined a function twice. My guess is that the compiler first translates the alias, loosing it, then it checks consistency. Maybe the compiler should check consistency with aliases, and give a better error message, something like "Remember that aliasing is not typedefing", but I guess that's too much. :-P

Ary
October 20, 2006
Ary Manzana wrote:

> "Remember that aliasing is not typedefing", but I
> guess that's too much. :-P

Especially when none of the overloaded functions is used anywhere.

I wouldn't want a nitpicking compiler.