You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently DMD does not allow returning auto when overriding a function.
Consider this case:
===========================================
interface Foo { /* some methods */ }
interface Bar { Foo getFoo(); }
class BarImpl: Bar
{
override auto getFoo()
{
class FooImpl: Foo
{
// implementation of Foo ...
// ... plus range methods
}
}
}
===========================================
Currently I have two options:
1) remove auto and return Foo instead; this way the user cannot use the range interface of FooImpl, because it receives a Foo
2) put FooImpl outside the function and return FooImpl; this way all functionality is correct, but it's not optimal as I have to put FooImpl outside the only function that uses it (which looks weird), plus FooImpl cannot implicitly access the getFoo context.
This is not a essential enhancement, I don't know if it is feasible to implement it, but it would make the language features more orthogonal, allowing the use of overriding with return type inference and voldemort types.
The text was updated successfully, but these errors were encountered:
> Currently I have two options:3) use structs (they are usually used for ranges anyways). With alias this and mixins you can get a pretty decent inheritance, but of course I don't know your code ;-)
(In reply to greenify from comment #1)
> > Currently I have two options:> > 3) use structs (they are usually used for ranges anyways). With alias this> and mixins you can get a pretty decent inheritance, but of course I don't> know your code ;-)
True in general, but not really an option for my code (I need a certain amount of runtime polymorphism).
Regardless of my example, which I solved with option 2, the question of this issue is "is this feasible to implement? If it is, why not have it? If it's not, fair enough."
> True in general, but not really an option for my code (I need a certain amount of runtime polymorphism).
I thought so :/
> Regardless of my example, which I solved with option 2, the question of this issue is "is this feasible to implement? If it is, why not have it? If it's not, fair enough."
I do agree that it's a bug / missing feature.
If you want to get" dirty" yourself, I can highly recommend Walter's video from Dconf16
Lodovico Giaretta reported this on 2016-08-16T09:19:02Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=16395
CC List
Description
The text was updated successfully, but these errors were encountered: