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

No warning given when self-assigment occurs #2137

Closed
DartBot opened this issue Nov 16, 2013 · 8 comments
Closed

No warning given when self-assigment occurs #2137

DartBot opened this issue Nov 16, 2013 · 8 comments

Comments

@DartBot
Copy link

DartBot commented Nov 16, 2013

This issue was originally filed by hugo6ferreir...@gmail.com


What steps will reproduce the problem?

  1. create a class with a member variable: int a
  2. create a member method with a parameter: method_x(int a)
  3. make an invalid (useless) assignment "a = a;" in that method

What is the expected output? What do you see instead?

I expect to get at least a warning because the code has no effect.
The code that should have been written would be "this.a = a;"

What version of the product are you using? On what operating system?
Dart Editor version 1.0.0_r30187 (DEV)
Dart SDK version 1.0.0.3_r30187
java version "1.7.0_45"
Linux 3.2.0-56-generic #­86-Ubuntu SMP x86_64 GNU/Linux

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Nov 16, 2013

This comment was originally written by googlegroups...@kaioa.com


A setter might have side-effects.

For example, if you do this in JavaScript:

    window.location = window.location;

It will reload the page.

Or if you do something like canvas.width = canvas.width, you'll clear the canvas.

Well, generally speaking, this is bad style, but it isn't necessarily a no-op.

@bwilkerson
Copy link
Member

We can certainly add a hint for cases where no getter or setter is being invoked, which is probably the most common occurrence of the problem.


Added this to the Later milestone.
Removed Type-Defect, Priority-Unassigned labels.
Added Type-Enhancement, Priority-Medium, Area-Analyzer, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Nov 16, 2013

This comment was originally written by hugo6ferr...@gmail.com


Ok, didn't consider side effects of setters.
As pointed out, maybe assignments that don't use getters/setters can be checked.
Will still be of use for avoiding a few bugs.

Thanks for the feedback.

@bwilkerson
Copy link
Member

Added Analyzer-Hint label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@srawlins srawlins transferred this issue from dart-lang/sdk Jun 8, 2020
@srawlins
Copy link
Member

srawlins commented Jun 8, 2020

I think the linter might already have a self-assignment lint? Maybe just for getters/setters?

@srawlins
Copy link
Member

no_self_assignments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants