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

Type parameters do not shadow library prefixes in instance creation expressions #33005

Closed
munificent opened this issue Apr 30, 2018 · 2 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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@munificent
Copy link
Member

Given:

// foo.dart
class Foo {}

And:

import "foo.dart" as T;

class Bar<T> {
  test() {
    new T.Foo(); // <--
  }
}

void main() {
  new Bar().test();
}

I expect an error on the marked line because T should refer to Bar's type parameter, not the import prefix T. Instead, all I get from analyzer is:

hint • Unused import: 'foo.dart' at temp.dart:1:8 • unused_import

If I use T inside test() in some other kind of expression, I get the expected error. I think it's only when used in a new ... expression that it doesn't get the scope right.

I stumbled onto this while converting the language_2/prefix negative tests to be multitests, so this is probably an ancient bug that was never caught because negative tests make it too easy to mistake the true cause of a failure.

@munificent munificent added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Apr 30, 2018
@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 1, 2018
@lrhn
Copy link
Member

lrhn commented May 1, 2018

This is a bug. There has been some confusion about whether prefixes were statically scoped in places where they needed to be prefixes (which this isn't, but something like new p.C.n() requires p to be a prefix), but the paragraphs saying that "Dart is lexically scoped" are unambiguous.

@bwilkerson bwilkerson added this to the Dart2.1 milestone Aug 29, 2018
@bwilkerson bwilkerson modified the milestones: Dart2.1, PostDart2.1 Sep 4, 2018
@stereotype441 stereotype441 self-assigned this Oct 17, 2018
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 17, 2020
@srawlins
Copy link
Member

Analyzer now reports:

error • The prefix 'T' can't be used here because it is shadowed by a local declaration. • a.dart:5:9 • prefix_shadowed_by_local_declaration

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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants