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

Fix: No more crashing on hovering bodies of nested match statements #2334

Merged
merged 6 commits into from
Jul 1, 2022

Conversation

MikaelMayer
Copy link
Member

Fixes #2333

This is a very substantial problem.
The body of a NestedMatchStmt was cloned when resolved, resulting in variables not being resolved in the original tree, which caused the LSP to crash when asking about their hovering information.

I added a test.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@MikaelMayer MikaelMayer self-assigned this Jun 30, 2022
@keyboardDrummer
Copy link
Member

Are the test failures are caused by the change?

@MikaelMayer
Copy link
Member Author

Are the test failures are caused by the change?

Yes. Good that they are caught. Since my change originally was not cloning the list, and some resolving step was actually modifying this list, it was crashing somewhere else.
I'm now trying with a shallow copy of this list to see.

@MikaelMayer MikaelMayer enabled auto-merge (squash) July 1, 2022 20:42
Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the new test succeeds, and all of the old ones still do, this looks good to me.

@MikaelMayer MikaelMayer merged commit 5487792 into master Jul 1, 2022
@MikaelMayer MikaelMayer deleted the fix-hover-nestedmatchstmt branch July 1, 2022 21:00
cpitclaudel added a commit that referenced this pull request Jul 22, 2022
feat: Add support for disjunctive (“or”) patterns

* `Source/Dafny/AST/DafnyAst.cs`
  (`DisjunctivePattern`): New subclass of `ExtendedPattern`.
  (`IsWildcardPattern`): New property.
* `Source/Dafny/AST/Printer.cs` (`PrintExtendedPattern`):
  Add support for disjunctive patterns.
* `Source/Dafny/Cloner.cs` (`CloneExtendedPattern`):
  Refactor, add support for disjunctive patterns.
* `Source/Dafny/Dafny.atg`
  (`ExtendedPattern`): Rename to `SingleExtendedPattern`.
  (`ExtendedPattern`): New production for `|`-separated patterns.
* `Source/Dafny/Resolver.cs`
  (`FreshTempVarName`): Refactor, remove obsolete comment.
* `Source/Dafny/Resolver.cs`
  (`RBranch`, `RBranchStmt`): Reject disjunctive patterns.
  (`RemoveIllegalSubpatterns`): New function to detect, report, and remove
  nested disjunctive patterns and variables in disjunctive patterns.
  (`FlattenDisjunctivePatterns`): New function to convert a single
  `DisjunctivePattern` into one extended pattern per alternative.
  (`FlattenNestedMatchCaseExpr`): New wrapper around
  `FlattenDisjunctivePatterns` for `NestedMatchCaseExpr`.
  (`CompileNestedMatchExpr`): Use it.
  (`FlattenNestedMatchCaseStmt`): New wrappers around
  `FlattenDisjunctivePatterns` for `NestedMatchCaseStmt`.
  (`CompileNestedMatchStmt`): Use it.
  (`CheckLinearExtendedPattern`): Check the branches of each disjunctive pattern
  separately.

Match bodies are not cloned because they are already resolved;
see #2334 for details.

Closes #2220.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on hover
3 participants