-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Enhancement: Base(child)
class object upcast
#16426
base: master
Are you sure you want to change the base?
Conversation
`FundamentalType(arg)` works, e.g. `int(2)`. `Enum(Enum.foo)` works, which does nothing - see: https://issues.dlang.org/show_bug.cgi?id=16346 Let's allow class instance upcasting without having to use `cast`. `cast` can be bug-prone, and upcasting is always fine. Here upcasting takes precedence over a static opCall.
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16426" |
Should |
|
@atilaneves The idea is to be able to do conversion as an expression, without a cast. Requiring a declaration breaks the flow of an expression, and pollutes the scope when the declaration is only used once. |
Which expressions would be common enough to warrant the enhancement? |
|
I still don't understand when/why/how this would be used/useful. |
This can be a simple library function: T identity(T)(T value) =>
value; Then, use without template argument deduction: identity!Base(derived) It is even usable with UFCS: f.identity!Base.g; |
Over-engineered solution for a problem that shouldn’t exist. Issuing an implicit conversion explicitly should be easy. |
FundamentalType(arg)
works, e.g.int(2)
.Enum(Enum.foo)
works, which does nothing - seecompilable/b16346.d
below and/or https://issues.dlang.org/show_bug.cgi?id=16346.Let's allow class instance upcasting without having to use
cast
-Base(child)
.cast
can be bug-prone, and upcasting is always fine. In generic code it's not always clear what a type resolves to, so avoidingcast
makes code reviews easier.Here upcasting takes precedence over a static opCall, but that could be swapped.