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

NullReferenceException when using :- with the type-system-refresh option #4731

Closed
amaurremi opened this issue Oct 31, 2023 · 0 comments · Fixed by #4734
Closed

NullReferenceException when using :- with the type-system-refresh option #4731

amaurremi opened this issue Oct 31, 2023 · 0 comments · Fixed by #4734
Assignees
Labels
crash Dafny crashes on this input, or generates malformed code that can not be executed kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking

Comments

@amaurremi
Copy link
Contributor

amaurremi commented Oct 31, 2023

Dafny version

4.3.0

Code to produce this issue

datatype Option<T> = Some(val: T) | None {
    predicate  IsFailure() {
       None?
    }
    
    function  PropagateFailure<V>(): Option<V>
      requires None?
    {
      None
    }

    function Extract(): T
      requires Some?
    {
      val
    }
}

function foo(): Option<bool> {
  var x: Option<bool> :- None;
  None
}

Command to run and resulting output

dafny /typeSystemRefresh:1 Test.dfy

Resulting in

Unhandled exception. System.AggregateException: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.)))
 ---> System.AggregateException: One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))
 ---> 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.PreTypeResolver.<>c__DisplayClass58_7.<ResolveExpression>b__6()
   at Microsoft.Dafny.PreTypeConstraints.ApplyGuardedConstraints()
   at Microsoft.Dafny.PreTypeConstraints.PartiallySolveTypeConstraints(String printableContext, Boolean makeDecisions)
   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 moduleName, Boolean isAnExport)
   at Microsoft.Dafny.ModuleDefinition.Resolve(ModuleSignature sig, ModuleResolver resolver, Boolean isAnExport)
   at Microsoft.Dafny.LiteralModuleDecl.Resolve(ModuleResolver resolver, CompilationData compilation)
   at Microsoft.Dafny.ModuleResolver.ResolveModuleDeclaration(CompilationData compilation, ModuleDecl decl)
   at Microsoft.Dafny.ProgramResolver.ResolveModuleDeclaration(CompilationData compilation, ModuleDecl decl)
   at Microsoft.Dafny.ProgramResolver.Resolve(CancellationToken cancellationToken)
   at Microsoft.Dafny.DafnyMain.<>c__DisplayClass5_0.<Resolve>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)


### What happened?

It appears that using a failure-with-update statement with the `typeSystemRefresh` option results in a null-reference exception. 

The error appears to originate from [referencing](https://github.com/dafny-lang/dafny/blob/master/Source/DafnyCore/Resolver/PreType/PreTypeResolve.Expressions.cs#L616) a field on the type of the right-hand side of the update statement, which is set to null.


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

Mac
@amaurremi amaurremi added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking crash Dafny crashes on this input, or generates malformed code that can not be executed labels Oct 31, 2023
RustanLeino added a commit that referenced this issue Nov 3, 2023
Fixes #4731

### How has this been tested?

As part of this PR, I also converted some of the `:-` related tests in
the `exceptions` folder.

<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Dafny crashes on this input, or generates malformed code that can not be executed kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants