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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4063 - [CTFE] key not found in AA gives bad error message
Summary: [CTFE] key not found in AA gives bad error message
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
Reported: 2010年04月05日 05:29 UTC by bearophile_hugs
Modified: 2015年06月09日 05:11 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010年04月05日 05:29:45 UTC
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.


AltStyle によって変換されたページ (->オリジナル) /