-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test.py error tests should support context messages from the CFE #44872
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
Comments
@munificent any progress on this? |
I made some progress today. I'm trying to figure out:
class C {
int? x;
// ^
// [cfe] Context: 'x' refers to a property so it couldn't be promoted.
f() {
if (x == null) return;
x.isEven;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
}
} Note the Another option is something more like: class C {
int? x;
// ^
// [cfe] Context: 'x' refers to a property so it couldn't be promoted.
f() {
if (x == null) return;
x.isEven;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
// [cfe context line 2, column 8] 'x' refers to a property so it couldn't be promoted.
}
} I think that's a little clearer, but it means changes to the test will change those line numbers. Of course, the test updater do this for you. @stereotype441 and @johnniwinther (and anyone else who cares about CFE static error tests), any thoughts or preferences? |
I prefer the format that doesn't have embedded line/column numbers for maintainability reasons, but I'm a little worried that it will get us into trouble by making the test ambiguous if there's multiple errors. How about an approach where we have numbered identifiers to point to the locations? Something like this: class C {
int? x;
// ^
// [cfe @1]
f() {
if (x == null) return;
x.isEven;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
// [cfe context @1] 'x' refers to a property so it couldn't be promoted.
}
} That way the |
I like that. I was idly considering something similar, so our convergent evolution here is a signal that it's a good idea. Let me see how hard that is to implement and I'll go from there. |
(Parent issue #44897)
As of a42244f, I've begun implementing "why not promoted" functionality in the CFE. For example, this code:
leads to the following output:
I tried to write a language test to validate this functionality (see https://dart-review.googlesource.com/c/sdk/+/182901) but test.py currently only supports testing the main error message; it ignores the "Context:" messages entirely. We need a way to test the context messages as well.
(Eventually we'll want to extend these tests to support analyzer as well, but some analyzer work needs to be done first, to get the context messages exposed in a machine readable way, so it makes sense to start with CFE support).
The text was updated successfully, but these errors were encountered: