[Issue 1399] Wrapping a case statement in a version statement gives a shadowing declaration error.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 7 00:46:31 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1399





------- Comment #3 from aziz.kerim at gmail.com  2007-08-07 02:46 -------
I think I can explain how the compiler understands the code I provided. Stewart
has observed correctly, that when you remove the version block the code
compiles without errors. This is because every case and default block
introduces a new scope (the switch block has its own scope as well.)

The two case blocks are similar to this code:

void func()
{
  // This is valid code.
  {
    auto a = 0;
  }
  {
    auto a = 0;
  }
}

The problem arises when you wrap the second case statement into a version
block, because then the version block plus the nested case block is contained
by the first case block. The reason for this is that the parses parses every
statement until it hits another case or default block.

The code with the version block would thus be seen by the compiler as:

void func()
{
  {
    auto a = 0;
  {
    auto a = 0; // Error: shadowing outer a
  }
  }
}

The following code generates the same error:

switch (1)
{
auto a = 0;
case 1:
  auto a = 1; // Error: shadowing declaration
default:
}


-- 



More information about the Digitalmars-d-bugs mailing list