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 null ref in covered tokens #5548

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Source/DafnyCore/AST/Members/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public TailStatus
public readonly Formal Result;
public PreType ResultPreType;
public readonly Type ResultType;
public readonly Specification<FrameExpression> Reads;
public Expression Body; // an extended expression; Body is readonly after construction, except for any kind of rewrite that may take place around the time of resolution
public IToken /*?*/ ByMethodTok; // null iff ByMethodBody is null
public BlockStmt /*?*/ ByMethodBody;
Expand Down
1 change: 0 additions & 1 deletion Source/DafnyCore/AST/Members/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ static Method() {
public bool MustReverify;
public bool IsEntryPoint = false;
public readonly List<Formal> Outs;
public readonly Specification<FrameExpression> Reads;
public readonly Specification<FrameExpression> Mod;
[FilledInDuringResolution] public bool IsRecursive;
[FilledInDuringResolution] public bool IsTailRecursive;
Expand Down
6 changes: 1 addition & 5 deletions Source/DafnyCore/AST/Members/MethodOrFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,5 @@ public void ResolveMethodOrFunction(INewOrOldResolver resolver) {
protected MethodOrFunction(RangeToken tok, Name name, bool hasStaticKeyword, bool isGhost, Attributes attributes, bool isRefining) : base(tok, name, hasStaticKeyword, isGhost, attributes, isRefining) {
}

public Specification<FrameExpression> Reads => this switch {
Method m => m.Reads,
Function f => f.Reads,
_ => throw new cce.UnreachableException()
};
public Specification<FrameExpression> Reads { get; set; }
}
3 changes: 3 additions & 0 deletions Source/DafnyCore/Generic/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public abstract class Node : INode {
public IEnumerable<IToken> CoveredTokens {
get {
var token = StartToken;
if (token == Token.NoToken) {
yield break;
}
while (token.Prev != EndToken) {
yield return token;
token = token.Next;
Expand Down
36 changes: 36 additions & 0 deletions Source/DafnyLanguageServer.Test/CodeActions/CodeActionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ public async Task MethodKeywordCodeAction() {
Assert.Empty(completionList);
}

[Fact]
public async Task TypeTestCodeAction() {
await SetUp(o => o.Set(CommonOptionBag.RelaxDefiniteAssignment, true));

MarkupTestFile.GetPositionsAndAnnotatedRanges(@"module M {
trait Object {
ghost function typeId() : (id: string)
}

type A extends Object {
ghost function typeId() : (id: string) { ""A"" }
}

type B extends Object {
ghost function typeId() : (id: string) { ""B"" }
}
type C extends Object {
ghost function typeId() : (id: string) { ""C"" }
}

lemma test(x: Object)
ensures multiset{x is A, x is B, x is C}[true] == 1
{
var _ := x.typeId();
if (x is A) {
assert x !is B.><
}
}
}".TrimStart(), out var source, out var positions,
out var ranges);
var documentItem = await CreateOpenAndWaitForResolve(source);
var position = positions[0];
var completionList = await RequestCodeActionAsync(documentItem, new Range(position, position));
Assert.Empty(completionList);
}

[Fact]
public async Task GitIssue4401CorrectInsertionPlace() {
await TestCodeAction(@"
Expand Down