www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Enums with same names in different classes

reply Mike Parker <aldacron71 yahoo.com> writes:
Attempting to compile the following with DMD 0.113 on Windows results in 
the error "no property 'Blarg' for type 'int'":

----------------------------------------------------
import std.stdio;

class Foo
{
public:
	enum MyEnum
	{
		Default,
		Blah
	}
}

class Bar
{
public:
	enum MyEnum
	{
		Default,
		Blarg
	}
}

void main()
{
	writefln("%d", cast(int)Foo.MyEnum.Default);
	writefln("%d", cast(int)Bar.MyEnum.Default);
	
	writefln("%d", cast(int)Foo.MyEnum.Blah);
	writefln("%d", cast(int)Foo.MyEnum.Blah);
	
	// comment out this next line and it will happily compile
	writefln("%d", cast(int)Bar.MyEnum.Blarg);
}

------------------------------------------------------

Commenting out the offensive line (the last writefln) causes it to 
compile and run, which utterly makes no sense!
Feb 14 2005
next sibling parent reply Mike Parker <aldacron71 yahoo.com> writes:
Mike Parker wrote:
----------------------------------------------------
class Foo
{
public:
	enum MyEnum
	{
		Default,
		Blah
	}
}

class Bar
{
public:
	enum MyEnum
	{
		Default,
		Blarg
	}
}

void main()
{
	writefln("%d", cast(int)Foo.MyEnum.Default);
	writefln("%d", cast(int)Bar.MyEnum.Default);
	
	writefln("%d", cast(int)Foo.MyEnum.Blah);
	// ooops, this line was wrong in the original
	// post. Notice that the Bar.MyEnum has no
	// value named 'Blah'
	writefln("%d", cast(int)Bar.MyEnum.Blah);
	
	// comment out this next line and it will happily compile and run
	writefln("%d", cast(int)Bar.MyEnum.Blarg);
}
------------------------------------------------------
Feb 14 2005
parent =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.THISISSPAM.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mike Parker wrote:
| Mike Parker wrote:
| ----------------------------------------------------
| class Foo
| {
| public:
|     enum MyEnum
|     {
|         Default,
|         Blah
|     }
| }
|
| class Bar
| {
| public:
|     enum MyEnum
|     {
|         Default,
|         Blarg
|     }
| }
|
| void main()
| {
|     writefln("%d", cast(int)Foo.MyEnum.Default);
|     writefln("%d", cast(int)Bar.MyEnum.Default);
|
|     writefln("%d", cast(int)Foo.MyEnum.Blah);
|     // ooops, this line was wrong in the original
|     // post. Notice that the Bar.MyEnum has no
|     // value named 'Blah'
|     writefln("%d", cast(int)Bar.MyEnum.Blah);
|
|     // comment out this next line and it will happily compile and run
|     writefln("%d", cast(int)Bar.MyEnum.Blarg);
| }
| ------------------------------------------------------

Added to DStress as
http://dstress.kuehne.cn/run/enum_13.d

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCFxIE3w+/yD4P9tIRAg9lAJ9n10saUN3YDYmqgNAGTYgSNhLZEACdGekk
it+THpDaxvu93md8WDPFfig=
=KKrZ
-----END PGP SIGNATURE-----
Feb 19 2005
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Mike Parker wrote:
[...] 
 which utterly makes no sense!
[...] Congratulation, you downsized the vanishing bug I described in: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/2873 -manfred
Feb 14 2005