Bug 4063 – [CTFE] key not found in AA gives bad error message

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-04-05T05:29:00Z
Last change time
2015-06-09T05:11:42Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-04-05T05:29:45Z
int foo(string s) { enum int[string] aa = ["aa":1, "bb":2]; return aa[s]; } enum _ = foo("xx"); // line 5 void main() {} dmd 2.042 gives: test.d(5): Error: cannot evaluate foo("xx") at compile time test.d(5): Error: cannot evaluate foo("xx") at compile time A much better pair of error messages can be: test.d(3): Error: Range violation. Key "xx" not found in associative array 'aa'. test.d(5): Error: cannot evaluate foo("xx") at compile time. Or just (if the symmetry with the run-time error is not considered important): test.d(3): key "xx" not found in associative array 'aa'. test.d(5): Error: cannot evaluate foo("xx") at compile time.
Comment #1 by clugdbug — 2011-06-17T01:08:40Z