Skip to content

Commit

Permalink
fix: Crash when compiling an empty source file while including testin…
Browse files Browse the repository at this point in the history
…g code
  • Loading branch information
fabiomadge committed Jul 19, 2024
1 parent 91d35a2 commit 8b04444
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Source/DafnyCore/AST/Statements/Assignment/AssignStmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ void ObjectInvariant() {

public override IToken Tok {
get {
var previous = Rhs.StartToken.Prev;
// If there was a single assignment, report on the operator.
var singleAssignment = previous.val == ":=";
// If there was an implicit return assignment, report on the return.
var implicitAssignment = previous.val == "return";
if (singleAssignment || implicitAssignment) {
return previous;
if (Rhs.StartToken.Prev is not null) {
var previous = Rhs.StartToken.Prev;
// If there was a single assignment, report on the operator.
var singleAssignment = previous.val == ":=";
// If there was an implicit return assignment, report on the return.
var implicitAssignment = previous.val == "return";
if (singleAssignment || implicitAssignment) {
return previous;
}
}
return Rhs.StartToken;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Rewriters/RunAllTestsMainMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal override void PreResolve(Program program) {
/// }
/// </summary>
internal override void PostResolve(Program program) {
var tok = program.GetStartOfFirstFileToken();
var tok = program.GetStartOfFirstFileToken() ?? Token.NoToken;
List<Statement> mainMethodStatements = new();
var idGenerator = new FreshIdGenerator();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: %translate cs --include-test-runner --allow-warnings %s > "%t"
// RUN: %diff "%s.expect" "%t"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
git-issue-5637.dfy(1,0): Warning: File contains no code
|
1 | // RUN: %translate cs --include-test-runner --allow-warnings %s > "%t"
| ^


Dafny program verifier finished with 0 verified, 0 errors
1 change: 1 addition & 0 deletions docs/dev/news/5638.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crash when compiling an empty source file while including testing code

0 comments on commit 8b04444

Please sign in to comment.