www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16395] New: auto return on override


          Issue ID: 16395
           Summary: auto return on override
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: spec
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lodovico giaretart.net

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.

Aug 16 2016