Why does this compile (method in class without return type)

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 3 01:10:04 PDT 2017


On Wednesday, 3 May 2017 at 07:37:31 UTC, Jacob Carlborg wrote:
> It might be by accident but I think the compiler is inferring 
> the return type. Just as "auto" is not necessary to infer the 
> type of a variable if there's another attribute:
>
> auto a = 3;
> const auto b = 4; // here "auto" is redundant
> const c = 5;
>
> In your case you have "final" as the attribute.

Yes, the compiler is inferring the return type. However, it 
_should_ be inferring it as void, and the override in B should 
then be illegal. If I stick

     pragma(msg, typeof(print));

right after each declaration for print, then it prints

@system void()

for A and

void()

for B, which is odd, since both should be @system. Interestingly, 
if both have pragmas at the same time, _then_ I get a compilation 
error:

qd.d(11): Error: function qd.B.print cannot override final 
function qd.A.print

So, I'd say that there's definitely a bug here.


More information about the Digitalmars-d-learn mailing list