Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for issue 3860 and resolve it #3867

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/DafnyCore/Resolver/Resolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ public class ModuleBindings {
// add deconstructors now (that is, after the query methods have been added)
foreach (DatatypeCtor ctor in dt.Ctors) {
var formalsUsedInThisCtor = new HashSet<string>();
var duplicates = new HashSet<Formal>();
foreach (var formal in ctor.Formals) {
MemberDecl previousMember = null;
var localDuplicate = false;
Expand All @@ -1837,6 +1838,7 @@ public class ModuleBindings {
if (localDuplicate) {
reporter.Error(MessageSource.Resolver, ctor,
"Duplicate use of deconstructor name in the same constructor: {0}", formal.Name);
duplicates.Add(formal);
} else if (previousMember is DatatypeDestructor) {
// this is okay, if the destructor has the appropriate type; this will be checked later, after type checking
} else {
Expand Down Expand Up @@ -1867,6 +1869,10 @@ public class ModuleBindings {

ctor.Destructors.Add(dtor);
}

foreach (var duplicate in duplicates) {
ctor.Formals.Remove(duplicate);
}
}

// finally, add any additional user-defined members
Expand Down
15 changes: 15 additions & 0 deletions Test/git-issues/github-issue-3860.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: ! %baredafny verify %args %s > %t
// RUN: %diff "%s.expect" "%t"

datatype Type =
| Cons()

datatype Test = Test(
y : Type,
y : Type
)

predicate pred(t: Test, t': Test)
{
&& t' == t.(y := Cons())
}
2 changes: 2 additions & 0 deletions Test/git-issues/github-issue-3860.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github-issue-3860.dfy(7,16): Error: Duplicate use of deconstructor name in the same constructor: y
1 resolution/type errors detected in github-issue-3860.dfy
1 change: 1 addition & 0 deletions docs/dev/news/3860.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent a compiler crash that could occur when a datatype constructor was defined that has multiple parameters with the same name.