-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
dart-model-analyzer-specIssues with the analyzer's implementation of the language specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.
Description
Thanks to @mraleph for discovering this issue, and @lrhn for bringing it to my attention.
The following code is accepted by the CFE but not the analyzer:
void main() {
f(('',), (s) { s.length; });
g([''], (s) { s.length; });
}
void f<T>((T,) v, void Function(T) fn) {
fn(v.$1);
}
void g<T>(List<T> v, void Function(T) fn) {
fn(v[0]);
}The analyzer reports the error:
error • test.dart:2:20 • The property 'length' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.') or adding a null check to the target ('!'). •
unchecked_use_of_nullable_value
The reason this is happening is that when examining the type signature for f, the analyzer fails to notice that the type variable T appears free in the type (T,), so when analyzing f(('',), (s) { s.length; }), it doesn't schedule a round of horizontal inference between analysis of ('',) and (s) { s.length; }.
I'm working on a fix.
FMorschel, ktkk and orestesgaolin
Metadata
Metadata
Assignees
Labels
dart-model-analyzer-specIssues with the analyzer's implementation of the language specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.