Skip to content

Analyzer throws exception if function optional argument is omitted and it's parametrized. #33864

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

Closed
iarkh opened this issue Jul 16, 2018 · 5 comments
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec legacy-area-analyzer Use area-devexp instead. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@iarkh
Copy link
Contributor

iarkh commented Jul 16, 2018

Dart SDK Version: 2.0.0_dev.68.0
OS: Windows 10

The following sample code example declares a function with one optional parametrized argument and than calls it without parameters:

class A<X> {}
testme<X extends A<X>>([X x]) {}

main() { testme(); }

It passes with dart and it seems like a correct result - indeed, if we don't set optional input argument, it should not affect the execution.
However, dartanalyzer throws an error here:

Analyzing test.dart...
  error - Couldn't infer type parameter 'X'.

Tried to infer 'A<dynamic>' for 'X' which doesn't work:
  Type parameter 'X' declared to extend 'A<A<dynamic>>'.

Consider passing explicit type argument(s) to the generic.

 at test.dart:4:10 - strong_mode_could_not_infer
1 error found.

I suppose analyzer should pass here too.

@iarkh
Copy link
Contributor Author

iarkh commented Jul 16, 2018

I've just found even more simple example which fails similarly - in the following code

testme1<X extends List<X>>() {}
testme2<X extends List<int>>() {}

main() {
  testme1();
  testme2();
}

analyzer passes with testme2() and fails with testme1().

@dgrove dgrove added the legacy-area-analyzer Use area-devexp instead. label Jul 19, 2018
@bwilkerson bwilkerson added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 28, 2018
@bwilkerson bwilkerson added this to the Dart2.1 milestone Aug 28, 2018
@devoncarew devoncarew modified the milestones: Dart2.1, PostDart2.1 Sep 5, 2018
@chloestefantsova
Copy link
Contributor

I'm implementing the checks of type arguments against the bounds in CFE currently and seeing tests with type variables declared like in the examples shown above (for example, X extends A<X>). I believe they indeed should be compile-time errors.

In the last example the missing compile-time argument provided by instantiate-to-bound is List<dynamic> for testme1, and it's a super-bounded type that could be used in many places. However, it does not pass the check against the bound, because List<dynamic> is not an f-bounded type and is not a subtype of List of itself, in particular.

Just in case I'm interpreting the feature spec incorrectly, I'll cc @eernstg.

@eernstg
Copy link
Member

eernstg commented Oct 5, 2018

Agreed, i2b makes it testme1<List<dynamic>>(), and that's a generic function invocation so its actual type argument must satisfy the declared bound.

In particular, the given type argument is passed and may be used by code which was checked statically under the assumption that type parameter bounds are satisfied, so it would be unsound to allow any bound violations. So super-bounded types can come up here, but they can't be allowed. Just like they can't be allowed as actual type arguments in an instance creation.

@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@srawlins srawlins added the P4 label Jan 11, 2021
@srawlins
Copy link
Member

Analyzer still produces could_not_infer error here.

@srawlins srawlins added the dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec label Aug 21, 2024
@srawlins
Copy link
Member

Dart2js now produces errors here, which I think agrees with @eernstg and @chloestefantsova 's assessment. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec legacy-area-analyzer Use area-devexp instead. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

8 participants