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

Analyzer doesn't properly implement horizontal inference when record types are involved #59933

Closed
stereotype441 opened this issue Jan 17, 2025 · 0 comments
Assignees
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@stereotype441
Copy link
Member

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.

@stereotype441 stereotype441 added analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Jan 17, 2025
@stereotype441 stereotype441 self-assigned this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

1 participant