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

Report a compile-time error when an expression of type void is used #54889

Open
eernstg opened this issue Feb 12, 2024 · 2 comments
Open

Report a compile-time error when an expression of type void is used #54889

eernstg opened this issue Feb 12, 2024 · 2 comments
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool)

Comments

@eernstg
Copy link
Member

eernstg commented Feb 12, 2024

An expression of type void cannot be used, unless it occurs in a situation which is specifically allow-listed.

The language test $SDK/tests/language/void/void_type_usage_test.dart is testing that these compile-time errors occur. This test used to have some faults (in particular, it was a multi test that used some labels more than once, which allowed some missing compile-time errors to go undetected).

The test is migrated to use the new test expectation syntax in https://dart-review.googlesource.com/c/sdk/+/350921 (that is // ^^^ to define the location and then // [cfe] ... and/or // [analyzer] ... to specify the expected error message).

With this test update, about 130 missing compile-time error failures exist with the analyzer and similarly for the common front end. This issue exists to indicate that those error messages should be emitted.

This issue awaits a breaking change process.

[Edit: This is not a breaking change, there were only a couple of test failures. Removing the 'status-blocked' label.]

Subtasks:

@eernstg eernstg added the area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). label Feb 12, 2024
@eernstg eernstg added the implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) label Feb 12, 2024
@eernstg eernstg added the status-blocked Blocked from making progress by another (referenced) issue label Feb 14, 2024
@eernstg
Copy link
Member Author

eernstg commented Feb 16, 2024

https://dart-review.googlesource.com/c/sdk/+/350921 has now been updated such that there are as few failures as possible.

In particular, many test failures were eliminated by relaxing the expected error messages. There is no more an expectation that all errors caused by a non-allowlisted usage of an expression of type void gives rise to a specific error message (that is, COMPILE_TIME_ERROR.USE_OF_VOID_RESULT from the analyzer, and This expression has type 'void' and can't be used. from the front end, which is the typical response). Instead, the error message which is actually emitted is accepted (they are all reasonable). So if there is a compile-time error at all then that test succeeds (but it is still necessary to change the test if a tool starts emitting some other message for the given situation, it's not specified as unspecified).

Next, many test failures were caused by a bug that I introduced when I changed the test from a multi-test to a test that uses the "// ^^^" style expectations: The expression of type void was in some cases a local variable x, and that local variable would soon get promoted from void to some other type (typically Object?). Hence, there were no void related error messages when x was used. This bug might have created the impression (during the past few days) that both the analyzer and the CFE failed to report an error in a large number of situations involving void expressions, and that isn't true, that was my bug. ;-)

With those two things in place, the resulting test only fails in a handful of cases, and only with the CFE.

The language team will probably discuss this topic on Wednesday, but it is probably not going to be a breaking change after all.

@eernstg eernstg removed the status-blocked Blocked from making progress by another (referenced) issue label Feb 28, 2024
@eernstg
Copy link
Member Author

eernstg commented Feb 28, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool)
Projects
None yet
Development

No branches or pull requests

1 participant