Skip to content

strict-inference doesn't complain about example given in its doc #45371

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

Open
goderbauer opened this issue Mar 19, 2021 · 2 comments
Open

strict-inference doesn't complain about example given in its doc #45371

goderbauer opened this issue Mar 19, 2021 · 2 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request type-documentation A request to add or improve documentation

Comments

@goderbauer
Copy link
Contributor

According to [1] the following should report an inference failure when strict-inference is turned on:

void main() {
  var a = [1, 2, 3].fold(true, (s, x) => s + x);
}

However, in an example project with the analysis_options.yaml file posted below no infernece issue is reported on Dart 2.13.0 (build 2.13.0-143.0.dev). (The only issue reported is an unused variable a.)

analyzer:
  language:
    strict-inference: true

[1] https://github.com/dart-lang/language/blob/master/resources/type-system/strict-inference.md#example-under-constrained-generic-method-invocations

/cc @srawlins

@goderbauer
Copy link
Contributor Author

This example given in the same doc also behaves differently then documented (differences noted in all-caps):

void f1(a) => print(a);           // Inference failure
void f2(var a) => print(a);       // Inference failure
void f3(final a) => print(a);     // Inference failure
void f4(int a) => print(a);       // OK
void f5<T>(T a) => print(a);      // OK
void f6([var a = 7]) => print(a); // Inference failure
void f7([int a = 7]) => print(a); // OK
void f8({var a}) => print(a);     // Inference failure
void f9({int a}) => print(a);     // OK

class C {
  C.x(var a) {}               // Inference failure <--- NO HINT PRODUCED
  C.y(int a) {}               // OK
  void f1(var a) => print(a); // Inference failure
  void f2(int a) => print(a);
}

class D extends C {
  @override
  void f2(a) => print(a); // OK <--- PRODUCES HINT
}

class E extends C {
  @override
  void f2(var a) => print(a); // OK <--- PRODUCES HINT
}

void fA(String cb(var a)) => print(cb(7)); // Inference failure
void fB(String cb(int x)) => print(cb(7)); // OK

// Typedef parameters cannot be specified with `var`.
typedef Callback = void Function(int); // OK

void main() {
  var f = (var a) {};      // Inference failure <--- NO HINT PRODUCED
  var g = (_, __, ___) {}; // OK
  fA((a) => a * a);        // OK
  fB((a) => a * a);        // OK
  Callback h = (var a) {}; // OK
}

@vsmenon vsmenon added the legacy-area-analyzer Use area-devexp instead. label Mar 19, 2021
@srawlins
Copy link
Member

I think the first issue mentioned is an issue with the impl. Most of the missing Hints in the doc you mention I think are issues with the doc, as these are lines where inference does not take place.

@srawlins srawlins added P3 A lower priority bug or feature request type-documentation A request to add or improve documentation labels Apr 1, 2021
dart-bot pushed a commit that referenced this issue May 26, 2021
The "inference failure" checks implemented here are long overdue. They
are part of the strict-inference spec [1]. I think I caught most function
invocation cases. All of the work done to determine which error to report
and whether @optionalTypeArgs is annotated is done _after_ the check
for whether strict-inference is enabled, so this should have no effect
on code which does not opt in to that mode.

[1] https://github.com/dart-lang/language/blob/master/resources/type-system/strict-inference.md#function-call

Bug: #33749 and
Change-Id: Ic1d4321fb289acb118e0dbddd48ff917ad39d69a
#45371
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201321
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
@srawlins srawlins added the devexp-warning Issues with the analyzer's Warning codes label Jul 19, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

4 participants