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

Hint to me when I have nullable fields in an object #57173

Closed
sethladd opened this issue Feb 13, 2015 · 4 comments
Closed

Hint to me when I have nullable fields in an object #57173

sethladd opened this issue Feb 13, 2015 · 4 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@sethladd
Copy link
Contributor

The following construct should be avoided:

class Thing {
  double x;
  double y;
  double z;

  Thing(this.x, this.y, this.z);
  Thing.empty() {}
}

Issues are:

  • x, y, and z could become null if Thing is constructed via empty().

The VM has a hard time optimizing fields that could be double or null. dart2js has a hard time optimizing field access that could be null.

Of course, I could set x,y,z to final. Or, I could eliminate empty() constructor.

@sethladd sethladd added the type-enhancement A request for a change that isn't a bug label Feb 13, 2015
@alan-knight
Copy link
Contributor

I'm curious what the story for suppressing lint warnings is going to be. This seems like a rule that's likely to give large numbers of warnings for things that are valid. For example, if I have Thing with no empty() constructor I might very well end up with a ThingBuilder which would have those warnings. Am I going to be able to indicate that particular uses are fine, or am I going to have to turn the rule off globally or else learn to ignore those warnings?

@sethladd
Copy link
Contributor Author

Good question! I don't know how one opts-into lints, especially ones that could have performance ramifications. Maybe the user makes an explicit request: "Show me lints that make the VM and dart2js happy"

@pq
Copy link
Member

pq commented Feb 13, 2015

Great question @alan-knight. There's the beginning of a conversation started over on #57153 but nothing is settled. Feel free to chime in!

@sethladd : wanna take a stab at a short description? For more context, I threw together some basic lint writing guidelines here. (Thanks for the nudge! 👍 )

@srawlins
Copy link
Member

Superseded by null safety.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants