Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use onRangeError in StringMap.opIndex #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/mir/string_map.d
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ struct StringMap(T, U = uint)
/++
Complexity: `O(log(s))`, where `s` is the number of the keys with the same length as the input key.
+/
ref inout(T) opIndex()(scope const(char)[] key) @trusted pure inout //@nogc
ref inout(T) opIndex()(scope const(char)[] key) @trusted pure inout nothrow @nogc
{
size_t index;
if (implementation && implementation.findIndex(key, index))
Expand All @@ -542,8 +542,9 @@ struct StringMap(T, U = uint)
assert (index < length);
return implementation._values[index];
}
import mir.exception: MirException;
throw new MirException("No member: ", key);
import core.exception : onRangeError;
onRangeError();
return implementation._values[0]; // TODO: remove when onRangeError is noreturn
}

version(mir_test) static if (is(T == int))
Expand Down