Bug 12939 – More uniform error messages for not nothrow and not @safe functions
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-17T17:26:00Z
Last change time
2016-10-01T11:47:32Z
Keywords
diagnostic, safe
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-06-17T17:26:41Z
void main() pure nothrow @safe @nogc {
import std.stdio;
writeln(1);
}
DMD 2.066alpha gives:
test.d(3,12): Error: pure function 'D main' cannot call impure function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: safe function 'D main' cannot call system function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: @nogc function 'D main' cannot call non-@nogc function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: 'std.stdio.writeln!(int).writeln' is not nothrow
test.d(1,6): Error: function 'D main' is nothrow yet may throw
I suggest error messages like (note the different single error message for nothrow, and the use of @safe/@system instead of safe/system):
test.d(3,12): Error: pure function 'D main' cannot call impure function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: nothrow function 'D main' cannot call non-nothrow function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: @safe function 'D main' cannot call @system function 'std.stdio.writeln!(int).writeln'
test.d(3,12): Error: @nogc function 'D main' cannot call non-@nogc function 'std.stdio.writeln!(int).writeln'
The error messages could even be compressed to reduce the noise:
test.d(3,12): Error: pure nothrow @safe @nogc function 'D main' cannot call impure non-nothrow @system non-@nogc function 'std.stdio.writeln!(int).writeln'