-
Notifications
You must be signed in to change notification settings - Fork 205
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
Specify implicit construction #3040
Conversation
The proposal should be complete enough to enable some discussions at this point. |
Thanks so much for putting this together @eernstg. There are many elements of this proposal I really like. I agree it's important to limit the scope of the implicit constructors. I think requiring a For example: import 'foo.dart';
show E implicit constructor Distance Function(int);
... I know my suggestion is very verbose, but just sharing the concept here 😄 We could also go further and limit conversions to different scope levels (library, class, or even method): @ImplicitConversions([Distance Function(int)]) // conversion allowed in this library
import '...';
...
@ImplicitConversions([Distance Function(double)]) // conversion only allowed in this class
class A {
...
@ImplicitConversions([Distance Function(String)]) // conversion only allowed in this method
m1() {
}
} Thoughts? On a separate note, this last week I came across interesting cases with int height = 0;
if (height == api.height /*returns JSNumber */) {
...
} What are your thoughts on possible ways in which |
@sigmundch wrote:
Interesting idea! We could allow implicit conversions to be enabled explicitly, and then have a lint catching the cases where it isn't used (a la "you're using this-and-that implicit constructor to convert [a specific expression], but that constructor hasn't been explicitly enabled"). // Library 'client.dart'.
import 'js_interop_static_extensions.dart' enable DoubleJsExtensions.fromDouble;
JSNumber jsNumber = ...;
double d = jsNumber; // Uses implicit conversion. We could also rely on the function type (here: This would again be a mechanism that we can leave out at first, and it could then be introduced later, and developers could make the choice about whether/when/where they'd enable the lint. For instance, there could be a library where certain conversions are used all the time, and
[Edit: changed my response here] I believe the position as the right operand of the If we do have an override like So we wouldn't have to do anything special about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review response (in this particular case I actually did not change the PR, but there's a discussion in #3095).
…most specific constructor
…d recommend a lint
b39c84a
to
b168793
Compare
Following the approach used with the primary constructor proposal, I'll land this document in 'working' at this time. |
This PR adds a proposal to the working directory about implicit constructors, provided as members of static extensions.