[Issue 16194] New: auto return type inference depends on return statement order
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Wed Jun 22 11:17:52 PDT 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=16194
          Issue ID: 16194
           Summary: auto return type inference depends on return statement
                    order
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: petar.p.kirov at gmail.com
void main()
{
    fun1(2); // Error: mismatched function return type inference
    fun2(2); // OK
}
class A {}
class B : A {}
class C : A {}
auto fun1(int a)
{
    if (a < 3)
        return new B();
    else if (a < 5)
        return new C();
    else
        return new A();
}
auto fun2(int a)
{
    if (a < 3)
        return new A();
    else if (a < 5)
        return new B();
    else
        return new C();
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list