Bug 10416 – Wrong error messages for inherited @safe class method

Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-06-19T10:46:00Z
Last change time
2013-06-19T12:18:50Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-06-19T10:46:41Z
import std.stdio: writeln; abstract class Foo { void spam() @safe; } class Bar : Foo { override void spam() { writeln; } } void main() {} DMD 2.063.2 gives the error message: temp.d(7): Error: safe function 'bug2.Bar.spam' cannot call system function 'std.stdio.writeln!().writeln' Even assuming that it's correct to label writeln() as a system function, Bar.foo is not labeled @safe. So I think the correct error message is similar to (note the use of system and @safe words below): test.d(6): Error: system function bug2.Bar.spam does not override any function, did you mean to override @safe function 'bug2.Foo.spam'?
Comment #1 by k.hara.pg — 2013-06-19T11:25:57Z
(In reply to comment #0) > import std.stdio: writeln; > abstract class Foo { > void spam() @safe; > } > class Bar : Foo { > override void spam() { > writeln; > } > } > void main() {} > > > > DMD 2.063.2 gives the error message: > > temp.d(7): Error: safe function 'bug2.Bar.spam' cannot call system function > 'std.stdio.writeln!().writeln' > > Even assuming that it's correct to label writeln() as a system function, > Bar.foo is not labeled @safe. So I think the correct error message is similar > to (note the use of system and @safe words below): > > > test.d(6): Error: system function bug2.Bar.spam does not override any function, > did you mean to override @safe function 'bug2.Foo.spam'? This is correct error message. Bar.spam is implicitly inherits @safe attriubte from Foo.spam. http://dlang.org/function#function-inheritance Then Bar.spam is implicitly annotated with @safe, and system function call will become invalid.
Comment #2 by bearophile_hugs — 2013-06-19T12:18:50Z
Thank you Kenji, my mistake.