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

Crash in new resolver #5369

Closed
keyboardDrummer opened this issue Apr 26, 2024 · 0 comments · Fixed by #5442
Closed

Crash in new resolver #5369

keyboardDrummer opened this issue Apr 26, 2024 · 0 comments · Fixed by #5442
Assignees
Labels
during 2: compilation of correct program Dafny rejects a valid program during compilation kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking priority: next Will consider working on this after in progress work is done

Comments

@keyboardDrummer
Copy link
Member

keyboardDrummer commented Apr 26, 2024

The following program crashes the resolver

ghost function f2(items: set<nat>): (r:nat)
  requires |items| > 0 {
    var item :| item in items;
    item
}

function f(items: set<nat>) : (r:nat)
requires |items| > 0 {
    //assume exists item :: item in items && forall other <- items :: item == other || item < other;
    //assert exists item Smallest()
    var item :| IsSmallest(items, item);
    item
}

predicate IsSmallest(s: set<nat>, item: nat) 
  requires item in s {
  m in s && forall y: nat :: y in s ==> m <= y
}

lemma Smallest(s: set<nat>) returns (m: nat)
  requires s != {}
  ensures m in s && IsSmallest(s, m)
  decreases s
{
  m :| m in s;
  if y: nat :| y in s && y < m {
    ghost var s' := s - {m};
    assert y in s';
    m := ThereIsASmallest(s');
  }
}

function smallest(items: set<nat>): (r: nat)
  requires |items| > 0

method m(items: set<nat>) returns (r:nat)
requires |items| > 0 {
    var item :| item in items;
    return item;
}

results in:

Dafny encountered an internal error. Please report it at <https://github.com/dafny-lang/dafny/issues>.
System.InvalidCastException: Unable to cast object of type 'Microsoft.Dafny.UnusedPreType' to type 'Microsoft.Dafny.DPreType'.
   at Microsoft.Dafny.PreTypeConstraints.ConfirmConstraint(CommonConfirmationBag check, PreType preType, DPreType auxPreType)
   at Microsoft.Dafny.PreTypeConstraints.ConfirmTypeConstraints()
   at Microsoft.Dafny.PreTypeConstraints.SolveAllTypeConstraints(String printableContext)
   at Microsoft.Dafny.PreTypeResolver.ResolveFunction(Function f)
   at Microsoft.Dafny.PreTypeResolver.ResolveMember(MemberDecl member)
   at Microsoft.Dafny.PreTypeResolver.ResolveDeclarationBody(Declaration d)
   at Microsoft.Dafny.PreTypeResolver.ResolveDeclarations(List`1 declarations, ModuleResolver resolver, Boolean firstPhaseOnly)
   at Microsoft.Dafny.ModuleResolver.ResolveTopLevelDecls_Core(List`1 declarations, Graph`1 datatypeDependencies, Graph`1 codatatypeDependencies, String moduleDescription, Boolean isAnExport)
   at Microsoft.Dafny.ModuleDefinition.Resolve(ModuleSignature sig, ModuleResolver resolver, String exportSetName)
   at Microsoft.Dafny.LiteralModuleDecl.Resolve(ModuleResolver resolver, CompilationData compilation)
   at Microsoft.Dafny.ModuleResolver.ResolveModuleDeclaration(CompilationData compilation, ModuleDecl decl)
   at Microsoft.Dafny.LanguageServer.Language.CachingResolver.ResolveModuleDeclaration(CompilationData compilation, ModuleDecl decl)
   at Microsoft.Dafny.ProgramResolver.Resolve(CancellationToken cancellationToken)
   at Microsoft.Dafny.LanguageServer.Language.CachingResolver.<>c__DisplayClass5_0.<Resolve>b__0()
   at Microsoft.Dafny.LanguageServer.Language.CachingResolver.Resolve(CancellationToken cancellationToken)
   at Microsoft.Dafny.LanguageServer.Language.Symbols.DafnyLangSymbolResolver.RunDafnyResolver(Compilation compilation, Program program, CancellationToken cancellationToken)
   at Microsoft.Dafny.LanguageServer.Language.Symbols.DafnyLangSymbolResolver.ResolveSymbols(Compilation compilation, Program program, CancellationToken cancellationToken)
   at Microsoft.Dafny.TextDocumentLoader.ResolveInternal(Compilation compilation, Program program, CancellationToken cancellationToken)
   at Microsoft.Dafny.TextDocumentLoader.<>c__DisplayClass5_0.<<ResolveAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Dafny.TextDocumentLoader.ResolveAsync(Compilation compilation, Program program, CancellationToken cancellationToken)
   at Microsoft.Dafny.Compilation.ResolveAsync()
@keyboardDrummer keyboardDrummer added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label priority: next Will consider working on this after in progress work is done during 2: compilation of correct program Dafny rejects a valid program during compilation part: resolver Resolution and typechecking labels Apr 26, 2024
@MikaelMayer MikaelMayer self-assigned this May 13, 2024
MikaelMayer added a commit that referenced this issue May 14, 2024
MikaelMayer added a commit that referenced this issue May 17, 2024
This PR fixes #5369
I added the corresponding test.


<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
during 2: compilation of correct program Dafny rejects a valid program during compilation kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking priority: next Will consider working on this after in progress work is done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants