Skip to content
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

auto return on override #19170

Open
dlangBugzillaToGithub opened this issue Aug 16, 2016 · 3 comments
Open

auto return on override #19170

dlangBugzillaToGithub opened this issue Aug 16, 2016 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

Lodovico Giaretta reported this on 2016-08-16T09:19:02Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=16395

CC List

  • Seb
  • Lodovico Giaretta

Description

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.
@dlangBugzillaToGithub
Copy link
Author

greeenify commented on 2016-08-16T09:48:23Z

> 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 ;-)

@dlangBugzillaToGithub
Copy link
Author

lodovico commented on 2016-08-16T10:05:50Z

(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."

@dlangBugzillaToGithub
Copy link
Author

greeenify commented on 2016-08-16T10:15:37Z

> 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant