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
Documentation on how to narrow types when using super parameters #50647
Comments
The lints are parts of the linter project, while the There is a fix to convert the code to const Bar(int super.value)
: _value = value; which would invoke |
Wow, I didn't know that. Thank you @asashour! I noticed just now that It should definitely be documented in the language tour or somewhere. It is a pity that it only prevents the parameter from being nullable and I still have to add a getter to make the value available as a non-null type. class Bar extends Foo {
const Bar(int super.value) : _value = value;
final int _value;
@override
int get value => _value; // This is still necessary.
} |
From Visual Studio Code or IntelliJ, you can open the quick fixes for the diagnostics (if applicable), without using Regarding int get value => _value;
|
Yep, I actually used the quick fix feature on IntelliJ instead of using the
I agree. It's just that I'm trying to do something unusual, so the linter is not the one to blame. I think the actual issue is only about documentation. |
use_super_parameters
warns where a super parameter is intentionally avoided
@atsansone @MaryaBelanger For feedback on documentation. |
On second thought, when you want the parameter to be non-null, I think you probably want the value to be accessed as non-null too. So the use case may not be so unusual. |
Since it's just docs, should we move the issue? I'm thinking either:
I don't understand the topic enough at this point to make the /linter or /site-www call, so if @bwilkerson or @kevmoo could make that call, I'll pick it up from there |
@kaboc If you have a minute, it'd be really interesting and valuable to hear how you navigated the problem when it first arose (if you remember, no worries if not) It seems like you noticed the quick fix after creating the issue, so before that and before creating this issue, did you get to look around the docs sites? For example,
This is just to help make sure the info ends up where users will naturally go looking for it, so any insight helps! Thanks |
@MaryaBelanger Thank you for the quick action. I appreciate the way you kindly listen to my experience to make improvements. It was actually several months ago that I first needed to solve the issue. I had already learned by then how to use super parameters, so I skipped the language tour, thinking there wouldn't be newly added descriptions. I tried the quick fix then. Although I don't remember clearly, I think it didn't work the same way it does now or I misunderstood it didn't work. So this was the second time I had needed a solution. I visited the language tour this time to see the latest info. It is the page I usually open first when I'm not sure about the grammar. I jump to more detailed pages from there.
I searched in the page with "super." with a dot at the end because it is always used in the
I only had a quick look at it to make sure the search navigated me to the relevant part of the page.
No, because I mainly looked at code pieces to find only the specific usage I needed. I would've read more closely and followed links if I had never read it before.
I didn't, because the issue was more about the grammar rather than the API. But I usually see the API doc when I want to learn a particular API.
Yes. I typed "super parameter" in the box in the top right corner of the language tour page. I believe the search box is not only for the tour page but for the entire dart.dev site. |
@bwilkerson I opened a doc issue, if you want to close this. I'll keep track over there if I think changes to the lint need to be made. @asashour qq: Where is the source of the quick fix associated with a lint? Is it written into the rule itself? I looked here: |
The mapping between lints (or any other kind of diagnostic) and their fixes is in the class FixProcessor. Open the file and search for the lint name to find the entry in the map. That will give you the name of the class (in the |
Bar
accepts only a value of typeint
, whileFoo
acceptsint?
. Theuse_super_parameter
rule warns there although it is intentional that I've avoidedsuper.value
so that thevalue
of Bar never becomes null.It is possible to suppress the warning with the
// ignore: use_super_parameter
comment, but it'll be better if the intention is considered. Is it too much for the analyzer to handle?The text was updated successfully, but these errors were encountered: