Skip to content

Analyzer type name clash disambiguator does not kick in when types are not exactly the same. #61556

@mraleph

Description

@mraleph

Make the following inputs:

// a.dart
class A {}
void foo(List<A> a) { }

// main.dart

import 'a.dart' as a;

class A {
}

void foo(List<A> listA, Iterable<A> iterableA) {
  a.foo(listA);
  a.foo(iterableA);
}

void main() {
}

Compare errors in analyzer and CFE:

$ dart analyze /tmp/main.dart
Analyzing main.dart...                 0.1s

  error • main.dart:8:9 • The argument type 'List<A> (where A is defined in /private/tmp/main.dart)' can't be
          assigned to the parameter type 'List<A> (where A is defined in /private/tmp/a.dart)'.  •
          argument_type_not_assignable
           - List is defined in /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/lib/core/list.dart at /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/lib/core/list.dart:120:26.
           - A is defined in /private/tmp/main.dart at main.dart:3:7.
           - List is defined in /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/lib/core/list.dart at /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/lib/core/list.dart:120:26.
           - A is defined in /private/tmp/a.dart at a.dart:1:7.
  error • main.dart:9:9 • The argument type 'Iterable<A>' can't be assigned to the parameter type 'List<A>'.
           • argument_type_not_assignable

2 issues found.
$ dart /tmp/main.dart
/tmp/main.dart:8:9: Error: The argument type 'List<A/*1*/>' can't be assigned to the parameter type 'List<A/*2*/>'.
 - 'List' is from 'dart:core'.
 - 'A/*1*/' is from '/tmp/main.dart'.
 - 'A/*2*/' is from '/tmp/a.dart'.
  a.foo(listA);
        ^
/tmp/main.dart:9:9: Error: The argument type 'Iterable<A/*1*/>' can't be assigned to the parameter type 'List<A/*2*/>'.
 - 'Iterable' is from 'dart:core'.
 - 'A/*1*/' is from '/tmp/main.dart'.
 - 'List' is from 'dart:core'.
 - 'A/*2*/' is from '/tmp/a.dart'.
  a.foo(iterableA);

The analyzer error for a.foo(iterableA); is not informative enough, because it does not provide the same level of details as other errors.

cc @johnniwinther - not sure how to properly triage it. I supposed it falls into model?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions