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

Analyzer fails to report error for import prefix hidden by class member (when used to name a type) #34500

Closed
stereotype441 opened this issue Sep 18, 2018 · 4 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)

Comments

@stereotype441
Copy link
Member

Consider the following code:

import 'dart:core';
import 'dart:core' as core;

class A {
  core.List get core => null; // (1)
}

Based on my reading of the spec, there should be a compile-time error at (1), because the declaration of the getter core inside of class A hides the import prefix declared at top level. So the type core.List should be invalid.

Oddly, the analyzer accepts this code without complaint, but it considers the return type of the getter to be the type dynamic.

Note that the front end's handling of this case isn't correct either--see #34498.

@stereotype441 stereotype441 added 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) labels Sep 18, 2018
@lrhn
Copy link
Member

lrhn commented Sep 18, 2018

This should indeed be a compile-time error.

@stereotype441
Copy link
Member Author

dart-bot pushed a commit that referenced this issue Sep 19, 2018
Also modify async_backwards_compatibility_1_test so that fixing these
bugs won't cause it to start failing.

Change-Id: I7bb3b9587a0aeea8662df1923034bcb409a29522
Reviewed-on: https://dart-review.googlesource.com/75280
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
@stereotype441
Copy link
Member Author

Note: a similar issue is #33005 (in that case, a type parameter fails to shadow the library prefix; in this one, a getter fails to shadow the library prefix).

@stereotype441 stereotype441 self-assigned this Oct 17, 2018
@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 'core' can't be used here because it is shadowed by a local declaration. • a.dart:5:3 • 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

3 participants