Skip to content

Commit

Permalink
Fixed bug in datatypes; duplicate constructor names were not being de…
Browse files Browse the repository at this point in the history
…tected.
  • Loading branch information
shazqadeer committed Jul 15, 2019
1 parent 5c829b6 commit 6d10336
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
14 changes: 11 additions & 3 deletions Source/Core/Absy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void Emit(TokenTextWriter stream) {
this.topLevelDeclarations.Emit(stream);
}

public void ProcessDatatypeConstructors() {
public void ProcessDatatypeConstructors(Errors errors) {
Dictionary<string, DatatypeConstructor> constructors = new Dictionary<string, DatatypeConstructor>();
List<Declaration> prunedTopLevelDeclarations = new List<Declaration>();
foreach (Declaration decl in TopLevelDeclarations) {
Expand All @@ -358,14 +358,22 @@ public void ProcessDatatypeConstructors() {
prunedTopLevelDeclarations.Add(decl);
continue;
}
if (constructors.ContainsKey(func.Name)) continue;
if (constructors.ContainsKey(func.Name))
{
errors.SemErr(func.tok, string.Format("more than one declaration of datatype constructor name: {0}", func.Name));
continue;
}
DatatypeConstructor constructor = new DatatypeConstructor(func);
constructors.Add(func.Name, constructor);
prunedTopLevelDeclarations.Add(constructor);
}
if (errors.count > 0)
{
return;
}

ClearTopLevelDeclarations();
AddTopLevelDeclarations(prunedTopLevelDeclarations);

foreach (DatatypeConstructor f in constructors.Values) {
for (int i = 0; i < f.InParams.Count; i++) {
DatatypeSelector selector = new DatatypeSelector(f, i);
Expand Down
13 changes: 7 additions & 6 deletions Source/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ public static int Parse (string s, string/*!*/ filename, out /*maybe null*/ Prog

Parser parser = new Parser(scanner, errors, false);
parser.Parse();
if (parser.errors.count == 0)
if (errors.count == 0)
{
program = parser.Pgm;
program.ProcessDatatypeConstructors();
return 0;
parser.Pgm.ProcessDatatypeConstructors(errors);
}
else
if (errors.count == 0)
{
program = parser.Pgm;
} else
{
program = null;
return parser.errors.count;
}
return errors.count;
}

public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors, bool disambiguation)
Expand Down
7 changes: 7 additions & 0 deletions Test/datatypes/t3.bpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %boogie -typeEncoding:m "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
type {:datatype} Value;
function {:constructor} Int(i: int): Value;

type {:datatype} Path;
function {:constructor} Int(i: int): Path;
2 changes: 2 additions & 0 deletions Test/datatypes/t3.bpl.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
t3.bpl(7,25): error: more than one declaration of datatype constructor name: Int
1 parse errors detected in t3.bpl

0 comments on commit 6d10336

Please sign in to comment.