Bug 12331 – Wrong error message for undefined identifier at compile-time

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-03-09T07:29:28Z
Last change time
2020-03-21T03:56:32Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-03-09T07:29:28Z
This is wrong code: int[] foo() { int[] result; result.reserve = 5; foreach (item; result) result ~= r; return result; } enum r = foo(); void main() {} dmd 2.066alpha gives an error message that I don't understand: test.d(1,7): Error: function test2.foo circular dependency. Functions cannot be interpreted while being compiled test.d(8,13): called from here: foo() test.d(8,13): called from here: foo() If I remove the compile-time call it gives the right error message: int[] foo() { int[] result; result.reserve = 5; foreach (item; result) result ~= r; return result; } //enum r = foo(); void main() {} test.d(5,19): Error: undefined identifier r
Comment #1 by nick — 2017-04-04T16:20:27Z
DMD 2.073.2 gives: f625.d(6): Error: circular initialization of variable 'f625.r' foo is allowed to read global enum r, so this seems correct behaviour. What else should be done?
Comment #2 by b2.temp — 2019-03-25T18:46:20Z
the message is good now