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

Unexpected behavior when renaming member on a class which inherits from a different package #25666

Closed
boasjls opened this issue Feb 3, 2016 · 2 comments
Assignees
Labels
analyzer-refactoring area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@boasjls
Copy link

boasjls commented Feb 3, 2016

Summary:
Rename/refactor has some unexpected, and potentially unwanted, behavior when working
with identifiers from a different package.

Specifically, in webstorm, if I have a class Foo that declares a member foo and
inherits from class Bar, where Bar is declared in a different package and declares a member bar,
then I can rename foo to bar such that the renamed foo now shadows the bar identifier from Bar.

This is not otherwise allowed if I declare the class Bar in same package as Foo, and could
potentially change the program semantics.

What steps will reproduce the problem?

  1. Create a package project 'awesome' in Webstorm. By default this project
    exports the following class
class Awesome {
  bool get isAwesome => true;
}
  1. Create a new simple command line project which imports the 'awesome' package.
    Change the contents of main.dart to the following:
import 'package:awesome/awesome.dart';

class MoreAwesome extends Awesome {
  bool get isNotAwesome => false;
}

main(List<String> args) {
  print(new MoreAwesome().isAwesome);
  print(new MoreAwesome().isNotAwesome);
}
  1. Use the rename function on the isNotAwesome identifier and rename it to isAwesome
    What is the expected output? What do you see instead?
    Expected:
    An error should be displayed - Renamed field will shadow getter 'isAwesome'.

Actual:
'isNotAwesome' is renamed to 'isAwesome' and running the program will now yield
the output

    false
    false

where it would previously yield

    true
    false

What version of the product are you using?
Dart SDK-1.15-dev.1.0

This appears to be a change that was introduced in Dart-1.14,
and it has been verified that is does not occur in Dart-1.13.

@boasjls boasjls changed the title Unexpected behavior when renaming class member which inherits from a different package Unexpected behavior when renaming member on a class which inherits from a different package Feb 3, 2016
@floitschG floitschG added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Feb 3, 2016
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed Priority-Medium labels Mar 1, 2016
@scheglov
Copy link
Contributor

scheglov commented Aug 3, 2016

I started working on this problem a while ago, but I don't remember whether I was able to reproduce it or not. But I cannot reproduce it now, so probably it was fixed.

Adding a new test for this case.
https://codereview.chromium.org/2204263002

scheglov added a commit that referenced this issue Aug 3, 2016
@scheglov
Copy link
Contributor

scheglov commented Aug 3, 2016

30b2401

@scheglov scheglov closed this as completed Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-refactoring area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants