-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Formatting within the IDE wasn't working anymore (#4274)
This PR fixes #4269 and fixes #4270 I first added unit tests for the cases that were failing. What really solved the issue was that I had to implement proper cloning for - methods, that were not keeping BodyStartTok - formals, that were not keeping RangeToken Then I also added for all formatting test a case when it tries to clone all members before formatting, like VSCode does, which unveiled 3 more formatting issues: ``` method Test() { g := new ClassName.ConstructorName( argument1b, // Two extra spaces argument2b, argument3b ); var g := new ClassName.ConstructorName( argument1, // Missing two extra spaces (when block mode activated) argument2, argument3 ); ... && unchanged( this, c ) && old( // Extra undesired space here c.c ) == c.c && fresh( c.c ) ``` I also solved the above issues by: * Ensuring the `RangeToken` of `TypeRHS` is preserved after cloning by modifying its topmost cloning parent `AssignmentRHS` * Ensure we iterate on pre resolved children to get `OwnedToken` (otherwise some cloned expressions were crashing) * Ensure `UnchangedExpr` is cloned with the same pattern as everyone else (otherwise the `RangeToken` wasn't kept) <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>
- Loading branch information
1 parent
12d49a7
commit d8c1135
Showing
18 changed files
with
290 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.Dafny; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Tomlyn; | ||
|
||
namespace DafnyCore.Test; | ||
|
||
public class ClonerTest { | ||
class DummyDecl : Declaration { | ||
public DummyDecl(Cloner cloner, Declaration original) : base(cloner, original) { | ||
} | ||
|
||
public DummyDecl(RangeToken rangeToken, Name name, Attributes attributes, bool isRefining) : base(rangeToken, name, | ||
attributes, isRefining) { | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClonerKeepsBodyStartTok() { | ||
var tokenBodyStart = new Token() { line = 2 }; | ||
var rangeToken = new RangeToken(Token.NoToken, Token.NoToken); | ||
var specificationFrame = new LiteralExpr(Microsoft.Dafny.Token.NoToken, 1); | ||
var formal1 = new Formal(Token.NoToken, "a", Microsoft.Dafny.Type.Bool, true, false, null) { | ||
RangeToken = new RangeToken(tokenBodyStart, tokenBodyStart), | ||
IsTypeExplicit = true | ||
}; | ||
var formal2 = new Formal(Token.NoToken, "b", Microsoft.Dafny.Type.Bool, true, false, null) { | ||
RangeToken = new RangeToken(tokenBodyStart, tokenBodyStart), | ||
IsTypeExplicit = false | ||
}; | ||
var dummyDecl = new Method(rangeToken, new Name(rangeToken, "hello"), | ||
false, false, new List<TypeParameter>(), new List<Formal> { formal1, formal2 }, | ||
new List<Formal>(), new List<AttributedExpression>(), | ||
new Specification<FrameExpression>(new List<FrameExpression>(), null), | ||
new List<AttributedExpression>(), new Specification<Expression>(new List<Expression>(), null), | ||
new BlockStmt(rangeToken, new List<Statement>()), null, Token.NoToken, false); | ||
|
||
dummyDecl.BodyStartTok = tokenBodyStart; | ||
var cloner = new Cloner(); | ||
var dummyDecl2 = cloner.CloneMethod(dummyDecl); | ||
Assert.Equal(2, dummyDecl2.BodyStartTok.line); | ||
Assert.Equal(2, dummyDecl2.Ins[0].RangeToken.StartToken.line); | ||
Assert.True(dummyDecl2.Ins[0].IsTypeExplicit); | ||
Assert.Equal(2, dummyDecl2.Ins[1].RangeToken.StartToken.line); | ||
Assert.False(dummyDecl2.Ins[1].IsTypeExplicit); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.