Skip to content

Commit

Permalink
Check for duplicate class name in different source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Apr 19, 2012
1 parent 6d71eb3 commit e1e9464
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mcs/errors/CS0101-7-2.cs
@@ -0,0 +1,5 @@
// CS0101: The namespace `global::' already contains a definition for `Test'
// Line: 5
// Compiler options: CS0101-7-2.cs

class Test {}
5 changes: 5 additions & 0 deletions mcs/errors/cs0101-7.cs
@@ -0,0 +1,5 @@
// CS0101: The namespace `global::' already contains a definition for `Test'
// Line: 5
// Compiler options: CS0101-7-2.cs

class Test {}
6 changes: 6 additions & 0 deletions mcs/mcs/class.cs
Expand Up @@ -70,6 +70,12 @@ public TypeContainer (TypeContainer parent, MemberName name, Attributes attrs, M
}
}

public Dictionary<string, MemberCore> DefinedNames {
get {
return defined_names;
}
}

public TypeDefinition PartialContainer {
get {
return main_container;
Expand Down
6 changes: 4 additions & 2 deletions mcs/mcs/namespace.cs
Expand Up @@ -799,8 +799,10 @@ public override void AddTypeContainer (TypeContainer tc)
name = mn.Name;
}

var names_container = Parent == null ? Module : (TypeContainer) this;

MemberCore mc;
if (defined_names.TryGetValue (name, out mc)) {
if (names_container.DefinedNames.TryGetValue (name, out mc)) {
if (tc is NamespaceContainer && mc is NamespaceContainer) {
containers.Add (tc);
return;
Expand All @@ -814,7 +816,7 @@ public override void AddTypeContainer (TypeContainer tc)
GetSignatureForError (), mn.GetSignatureForError ());
}
} else {
defined_names.Add (name, tc);
names_container.DefinedNames.Add (name, tc);
}

base.AddTypeContainer (tc);
Expand Down

1 comment on commit e1e9464

@spencerhakim
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke class definitions in REPL for partial/multi-line inputs, since the class name is added to DefinedNames before the full input is available. Easily tested with

class Test{
}

which reports

(1,8): error CS0101: The namespace `global::' already contains a definition for `Test'
(1,8): (Location of the symbol related to previous error)

Please sign in to comment.