Confusing follow-on errors when a const makes explicit use of a type parameter #33440
Labels
analyzer-constants
devexp-ux
legacy-area-analyzer
Use area-devexp instead.
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Related to #33439, sometimes the analyzer produces strange and surprising follow-on errors when a const makes explicit use of a type parameter. For example, consider this code from the regression test for #26141:
This code is invalid due to the fact that it makes use of type parameters in const expressions at
(1)
,(2)
,(3)
,(4)
, and(5)
. Those errors are not reported due to #33439. I will shortly be publishing a CL that causes the analyzer to print the following results when analyzing this code in strong mode:A value of type 'List<Q>' can't be assigned to the field 'list', which has type 'List<R>
(at(1)
)Evaluation of this constant expression throws an exception
(at(2)
)Evaluation of this constant expression throws an exception
(at(3)
)Evaluation of this constant expression throws an exception
(at(5)
)Note: these are currently reported as
info
rather thanerror
due to one of the root causes of #33304. Once that is fixed, and #33439 is fixed, they will show up as follow-on errors, making it more difficult for the user to figure out what the actual problem is. It would be far better if, once the analyzer detects an incorrect use of a type parameter in a const expression, it would recover by taking the least closure of the invalid type (similar to what it should do when the types are inferred--see #32918). That should prevent any follow-on errors from being reported.The text was updated successfully, but these errors were encountered: