Created attachment 644
Patch for dmd svn r502
This code is correctly rejected:
-------------------- test1.d
void main()
{
{ void foo() {} }
{ void foo() {} }
}
--------------------
% dmd test1
test1.d(4): Error: declaration foo is already defined in another scope in main
--------------------
However the following is accepted and link fails due to the name conflict.
-------------------- test2.d
void main()
{
{ typedef int T = 1; T v; assert(v == 1); }
{ struct T { int a = 2; } T v; assert(v.a == 2); }
{ union T { int a = 3; } T v; assert(v.a == 3); }
{ class T { int a = 4; } T v; assert(v.a == 4); }
{ enum T { a = 5 } T v; assert(v == 5); }
}
--------------------
% dmd test2
test2.o(.rodata+0x14): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
test2.o(.rodata+0x18): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
test2.o(.rodata+0x20): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
--------------------
The attached patch fixes the problem by rejecting such cases.
--------------------
% dmd test2
test2.d(4): Error: declaration T is already defined in another scope in main
test2.d(5): Error: declaration T is already defined in another scope in main
test2.d(6): Error: declaration T is already defined in another scope in main
test2.d(7): Error: declaration T is already defined in another scope in main
--------------------