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
feat: add common properties with different nullability to base mixin #740
Conversation
d3e1b9c
to
14343aa
Compare
In theory, we could also add all properties that are not common in all constructors and do not have a type conflict to the base mixin as nullable. What do you think? @rrousselGit? |
Also instead of removing properties with different nullability, we could add them but only allow non-null inputs. |
I went ahead and implemented that feature as well |
I don't think this closes #715 which is requesting for a common base class, whereas this just addresses the nullability aspect. This is a great first step though! |
You're right I read that issue a while ago and needed this specific feature now so I went ahead and implemented it. I vaguely remembered reading something about it and therefore just quickly added the closing statement without re-reading the original issue. Removed the closing statement since it is out of scope for what I currently require and would also require a lot more work. |
Hello! Thanks for your work! Supporting cases like: factory Foo.first(int a) = _First;
factory Foo.second(double a) = _Second;
...
Foo foo;
num a = foo.a; should not be as complex as I originally thought. I later learned about It's probably worth using that directly instead. |
If you haven't started working on that I can give it a go and try to refactor this PR to use |
Sure, go ahead 😄 |
Properties with a common super type that isn't I have not included them in the |
I also noticed that the |
Great! The super syntax isn't used yet because Freezed supports an sdk version lower than 2.17 It's not very important considering the code is generated |
I'm a bit busy until the Flutter Viking talks the 1st of September. Not sure I'll be able to properly review this PR before But thanks a lot for your work 😊 |
packages/freezed/test/integration/single_class_constructor.dart
Outdated
Show resolved
Hide resolved
@rrousselGit I'm happy to help review PRs if you are busy with other things. Excited for this PR! |
@TimWhiting Sure go ahead! I should be a bit more available by September. |
@rrousselGit all two types have As an example take: factory Foo.first(String a) = _First;
factory Foo.second(double a) = _Second;
Foo foo;
Object a = foo.a; Also, would a parameter be in the base mixin if all or one was typed with |
If all the cases possess the same variable, I think showing Object/Object? is fine. |
There are a few conflicts and some small tests changes. But otherwise LGTM! Thanks for your work 😄 |
…pr/DevNico/740
Looking back at the logic for obtaining the common subtype between union cases, the logic seems to do more than necessary Typedefs and generated types are not supported by Freezed in general. Trying to support it for this specific case doesn't make sense, as they are still unsupported for everything else. |
Alright, time to merge this! Sorry for the delay :) |
The new field
isCommonWithDifferentNullability
might not be perfect but it was the best way I could come up with to propagate the information.