Bug 9620 – Error messages of failed pure enforcement

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-28T19:59:00Z
Last change time
2015-02-18T03:37:34Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-02-28T19:59:45Z
I don't know if this is a bug, or if it's OK. This is wrong code: import std.range: chain; void main() pure { static void foo() { int[] a; chain(a, a); } foo(); } DMD 2.063alpha gives: test1.d(5): Error: pure function 'main' cannot call impure function 'chain' Is it right for the error message to say that main calls chain (while it's called by foo)? This similar code is a simpler example: void foo(int[]) {} void main() pure { static void bar() { int[] a; foo(a); } bar(); } It gives: test2.d(5): Error: pure function 'D main' cannot call impure function 'test2.foo' Note how in the first error message dmd uses 'main' and in the second 'D main'. I don't know why there is such difference.
Comment #1 by yebblies — 2013-11-16T21:41:25Z
The error messages now match, but still refer to the outer function instead of the nested one. https://github.com/D-Programming-Language/dmd/pull/2790
Comment #2 by github-bugzilla — 2014-11-13T10:59:25Z
Comment #3 by bearophile_hugs — 2014-11-13T12:27:32Z
Are you sure the bug is fixed correctly? Why is foo() not raising an error? If I comment out the call to bar() the main compiles, but it's not pure: int x; void bar() { x++; } void main() pure { static void foo() { x++; } foo(); // No error bar(); // Error } Gives: test.d(10,8): Error: pure function 'D main' cannot call impure function 'test.bar'
Comment #4 by yebblies — 2014-11-13T12:39:13Z
(In reply to bearophile_hugs from comment #3) > Are you sure the bug is fixed correctly? Why is foo() not raising an error? > If I comment out the call to bar() the main compiles, but it's not pure: > > > int x; > void bar() { > x++; > } > void main() pure { > static void foo() { > x++; > } > foo(); // No error > bar(); // Error > } > > > Gives: > > test.d(10,8): Error: pure function 'D main' cannot call impure function > 'test.bar' Heh that sure looks wrong to me. Although it's most likely not this same diagnostic issue.
Comment #5 by bearophile_hugs — 2014-11-13T12:40:38Z
(In reply to yebblies from comment #4) > Heh that sure looks wrong to me. Although it's most likely not this same > diagnostic issue. OK, then I'll open a different bug report.
Comment #6 by github-bugzilla — 2015-02-18T03:37:34Z