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: Crash when compiling an empty source file while including testing code #5638

Merged
merged 1 commit into from
Jul 22, 2024
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
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
Loading