[cfe] Spurious claim that a late final variable is 'definitely unassigned' #52704
Labels
area-front-end
Use area-front-end for front end / CFE / kernel format related issues.
improve-diagnostics
Related to the quality of diagnostic messages
Consider the following program:
This program is rejected with two compile-time errors by the CFE (DartPad, Based on Flutter 3.12.0-2.0.pre Dart SDK 3.1.0-169.0.dev):
The first error is fine, we may iterate more than once with the loop, and at the 2nd iteration and up we will assign a value to
x
even though it is definitely already assigned. (We could allow this because the loop might run exactly once; but this is hardly a useful treatment of the loop because it doesn't have to be a loop in the first place if it must run exactly once; so the error is indeed fine).It is also possible that the loop iterates zero times, in which case
x
remains unassigned. Soprint(x)
might fail. However,x
should be considered 'possibly assigned' atprint(x)
because it is possible that the loop runs exactly once.Note that the analyzer does not report any 'definitely unassigned' errors for this program.
Perhaps this is just caused by a kind of recovery where the await-for statement is considered to be a compile-time error, and then it is ignored during analysis of successors in the control flow graph?
The text was updated successfully, but these errors were encountered: