[Issue 17992] auto return type and null for classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 14 10:29:43 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=17992

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
Reduced test case:

class V
{}

auto foo(int a)
{
    if (a == 1)
        return null;

    pragma(msg, typeof(return));
    return new V();
}

void main()
{}

prints: typeof(null)

I'm not sure if this bug is valid. When semantic analysis is performed at the
point where typeof is evaluated the inference of the return type of foo (in
both examples) has only seen return statements of null. This makes inference
deduce that the type of foo is typeof(null) and this is true for that
particular point.
Changing this would require moving the typeof logic from semantic1 to semantic2
or semantic3 so that when typeof is encountered, the whole foo function has
been typechecked.

--


More information about the Digitalmars-d-bugs mailing list