[Issue 17366] New: Inferrence results in a missing error for final
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed May 3 01:20:18 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17366
Issue ID: 17366
Summary: Inferrence results in a missing error for final
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: issues.dlang at jmdavisProg.com
This code
import std.stdio;
class A
{
final print() { writeln(this); } // no return type
}
class B : A
{
final void print() { writeln(this); }
}
void main()
{
auto b = new B;
b.print();
A a1 = b;
a1.print();
A a2 = new A;
a2.print();
}
compiles and runs, giving
q.B
q.B
q.A
as output. Putting
pragma(msg, typeof(print));
after the declartion for A.print results in compilation printing
@system void()
q.d(11): Error: function q.B.print cannot override final function q.A.print
whereas putting the same pragma after B.print results in
void()
If A.print is changed to have void, then you get the error and the type that's
printed is the same as B.print.
I find it odd that @system void() and void() would any different, since the
default is @system - so that may or may not be a bug - but it's definitely a
bug that there isn't a compilation error in all cases, since A.print is final
and returns the same type as B.print (whether inferrence is involved or not).
The fact that whether the pragma is there or not affects whether you get a
compilation error is particularly disturbing, but it's a bug regardless.
--
More information about the Digitalmars-d-bugs
mailing list