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

Bad inference of default calc operator causes crash #3962

Closed
RustanLeino opened this issue May 5, 2023 · 0 comments · Fixed by #3963
Closed

Bad inference of default calc operator causes crash #3962

RustanLeino opened this issue May 5, 2023 · 0 comments · Fixed by #3963
Assignees
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

4.0.0

Code to produce this issue

method Issues(a: bool, s: set) {
  // Any one of the following 8 lines causes a crash

  calc { a; <== false; }
  calc { true; <== a; }
  calc { a; ==> true; }
  calc { false; ==> a; }

  calc { s; >= ({}); }
  calc { s; > ({}); }
  calc { {}; <= s; }
  calc { {}; < s; }
}

Command to run and resulting output

% dafny verify test.dfy
Unhandled exception. System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Dafny.Resolver.ResolveStatement(Statement stmt, ResolutionContext resolutionContext)
   at Microsoft.Dafny.Resolver.ResolveStatementWithLabels(Statement stmt, ResolutionContext resolutionContext)
   at Microsoft.Dafny.Resolver.ResolveBlockStatement(BlockStmt blockStmt, ResolutionContext resolutionContext)
   at Microsoft.Dafny.Resolver.ResolveMethod(Method m)
   at Microsoft.Dafny.Resolver.ResolveClassMemberBodies(TopLevelDeclWithMembers cl)
   at Microsoft.Dafny.Resolver.ResolveNamesAndInferTypesForOneDeclaration(TopLevelDecl topd)
   at Microsoft.Dafny.Resolver.ResolveNamesAndInferTypes(List`1 declarations, Boolean initialRound)
   at Microsoft.Dafny.Resolver.ResolveTopLevelDecls_Core(List`1 declarations, Graph`1 datatypeDependencies, Graph`1 codatatypeDependencies, Boolean isAnExport)
   at Microsoft.Dafny.Resolver.ResolveModuleDefinition(ModuleDefinition m, ModuleSignature sig, Boolean isAnExport)
   at Microsoft.Dafny.Resolver.ResolveProgram(Program prog)
   at Microsoft.Dafny.Main.Resolve(Program program, ErrorReporter reporter)
   at Microsoft.Dafny.DafnyDriver.ProcessFilesAsync(IList`1 dafnyFiles, ReadOnlyCollection`1 otherFileNames, ErrorReporter reporter, Boolean lookForSnapshots, String programId)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Microsoft.Dafny.DafnyDriver.ThreadMain(String[] args)
   at Microsoft.Dafny.DafnyDriver.<>c__DisplayClass10_0.<Main>b__0()
   at System.Threading.Thread.StartCallback()

What happened?

When a calc statement does not explicitly give a default operator, Dafny picks one. It usually picks ==, but in the 8 cases shown above (which start or end with the literal false, true, or {}), Dafny considers the candidate ==> for the first two, <== for the next two, <= for the next two, and >= for the final two.

Dafny 4.0 then picks that candidate operator as the calc statement's default operator. In the examples above, the candidate operator is in conflict with the given step operators (for example, ==> is not allowed to be chained with <==), which causes a crash.

The right thing to do is to discard the candidate operator if it would lead to such conflicts (and instead pick == as usual in those cases).

What type of operating system are you experiencing the problem on?

Mac

@RustanLeino RustanLeino added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label May 5, 2023
@RustanLeino RustanLeino self-assigned this May 5, 2023
RustanLeino added a commit to RustanLeino/dafny that referenced this issue May 5, 2023
RustanLeino added a commit to RustanLeino/dafny that referenced this issue May 5, 2023
RustanLeino added a commit that referenced this issue May 9, 2023
Fixes #3962


<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>

---------

Co-authored-by: Remy Willems <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant