Skip to content

Commit ac1889a

Browse files
committed
Type stability
1 parent abbcdec commit ac1889a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/register_units.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@ end
5252
function _register_unit(name::Symbol, value)
5353
name_symbol = Meta.quot(name)
5454
index = get(ALL_MAPPING, name, INDEX_TYPE(0))
55-
if iszero(index)
56-
reg_expr = _lazy_register_unit(name, value)
57-
push!(reg_expr.args, quote
58-
$update_all_values($name_symbol, $value)
59-
nothing
60-
end)
61-
return reg_expr
62-
else
55+
if !iszero(index)
6356
unit = ALL_VALUES[index]
6457
# When a utility function to expand `value` to its final form becomes
6558
# available, enable the following check. This will avoid throwing an error
6659
# if user is trying to register an existing unit with matching values.
6760
# unit.value != value && throw("Unit $name is already defined as $unit")
68-
throw("Unit `$name` is already defined as `$unit`")
61+
error("Unit `$name` is already defined as `$unit`")
6962
end
63+
reg_expr = _lazy_register_unit(name, value)
64+
push!(
65+
reg_expr.args,
66+
quote
67+
$update_all_values($name_symbol, $value)
68+
nothing
69+
end
70+
)
71+
return reg_expr
7072
end

src/write_once_read_many.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Base.get(w::WriteOnceReadMany{<:Dict}, a, b) = get(w._raw_data, a, b)
2323

2424
# Only define setindex! for Dicts, and throw an error if the key already exists
2525
function Base.setindex!(w::DynamicQuantities.WriteOnceReadMany{<:Dict}, i, s::Symbol)
26-
haskey(w._raw_data, s) && throw("Unit $s already exists at index $(w[s])")
26+
haskey(w._raw_data, s) && error("Unit $s already exists at index $(w[s])")
2727
setindex!(w._raw_data, i, s)
2828
return w
2929
end

0 commit comments

Comments
 (0)