Skip to content

Analyzer throws error when try to assign a function result to row variable. #33805

Open
@iarkh

Description

@iarkh

Dart SDK Version: 2.0.0-dev.55.0
OS: Windows 10

The following code sample assign a parametrized function result to the row variable:

class A<X> {}
X testme<X extends A<X>>() { return null; }
main() {
  A a = testme();
}

Dart and dartanalyzer show different results here: test passes without errors or warnings whereas dartanalyzer throws compiler error:

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>>'.
The type 'A<dynamic>' was inferred from:
  Return type declared as 'X'
              used where  'A<dynamic>' is required.

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

 at test.dart:4:9 - strong_mode_could_not_infer
  hint - The value of the local variable 'a' isn't used at test.dart:4:5 - unused_local_variable
1 error and 1 hint found.

I believe both tools should behave in a similar way.

Seems like A a = testme(); is OK and should pass in both cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions