D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7605 - Better error message when variable declaration hides type declaration
Summary: Better error message when variable declaration hides type declaration
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-28 09:22 UTC by Andrej Mitrovic
Modified: 2012-02-28 15:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-02-28 09:22:11 UTC
module test;

struct Foo { }
void main()
{
    Foo x;
    int Foo;
    Foo y;  // Error: Foo is used as a type
}

Compare the above to this:

module a;
int Foo;

module b;
struct Foo { }

module main;

import a;
import b;

void main() {
    Foo m;
}

main.d(7): Error: a.Foo at a.d(2) conflicts with b.Foo at b.d(2)
main.d(7): Error: Foo is used as a type

The first code example could instead output:
test.d(8): Error: test.Foo at test.d(3) conflicts with test.Foo at test.d(7)
test.d(8): Error: Foo is used as a type
Comment 1 Walter Bright 2012-02-28 15:34:15 UTC
But it doesn't conflict. They are in different scopes, one nested inside the other. The nested one overrides the outer one - not conflicts with it.