90
90
# give Enum types scalar behavior in broadcasting
91
91
Base. broadcastable (x:: Enum ) = Ref (x)
92
92
93
- @noinline enum_argument_error (typename, x) = throw (ArgumentError (string (" invalid value for Enum $( typename) : $x " )))
93
+ @noinline enum_argument_error (typename, x) = throw (ArgumentError (LazyString (" invalid value for Enum " , typename, " : " , x )))
94
94
95
95
"""
96
96
@enum EnumName[::BaseType] value1[=x] value2[=y]
@@ -143,18 +143,19 @@ julia> Symbol(apple)
143
143
"""
144
144
macro enum (T:: Union{Symbol,Expr} , syms... )
145
145
if isempty (syms)
146
- throw (ArgumentError (" no arguments given for Enum $T " ))
146
+ throw (ArgumentError (LazyString ( " no arguments given for Enum " , T) ))
147
147
end
148
148
basetype = Int32
149
149
typename = T
150
150
if isa (T, Expr) && T. head === :(:: ) && length (T. args) == 2 && isa (T. args[1 ], Symbol)
151
151
typename = T. args[1 ]
152
152
basetype = Core. eval (__module__, T. args[2 ])
153
153
if ! isa (basetype, DataType) || ! (basetype <: Integer ) || ! isbitstype (basetype)
154
- throw (ArgumentError (" invalid base type for Enum $typename , $T =::$basetype ; base type must be an integer primitive type" ))
154
+ throw (ArgumentError (
155
+ LazyString (" invalid base type for Enum " , typename, " , " , T, " =::" , basetype, " ; base type must be an integer primitive type" )))
155
156
end
156
157
elseif ! isa (T, Symbol)
157
- throw (ArgumentError (" invalid type expression for enum $T " ))
158
+ throw (ArgumentError (LazyString ( " invalid type expression for enum " , T) ))
158
159
end
159
160
values = Vector {basetype} ()
160
161
seen = Set {Symbol} ()
@@ -169,32 +170,32 @@ macro enum(T::Union{Symbol,Expr}, syms...)
169
170
s isa LineNumberNode && continue
170
171
if isa (s, Symbol)
171
172
if i == typemin (basetype) && ! isempty (values)
172
- throw (ArgumentError (" overflow in value \" $s \" of Enum $typename " ))
173
+ throw (ArgumentError (LazyString ( " overflow in value \" " , s, " \" of Enum " , typename) ))
173
174
end
174
175
elseif isa (s, Expr) &&
175
176
(s. head === :(= ) || s. head === :kw ) &&
176
177
length (s. args) == 2 && isa (s. args[1 ], Symbol)
177
178
i = Core. eval (__module__, s. args[2 ]) # allow exprs, e.g. uint128"1"
178
179
if ! isa (i, Integer)
179
- throw (ArgumentError (" invalid value for Enum $ typename , $s ; values must be integers" ))
180
+ throw (ArgumentError (LazyString ( " invalid value for Enum " , typename, " , " , s, " ; values must be integers" ) ))
180
181
end
181
182
i = convert (basetype, i)
182
183
s = s. args[1 ]
183
184
hasexpr = true
184
185
else
185
- throw (ArgumentError (string (" invalid argument for Enum " , typename, " : " , s)))
186
+ throw (ArgumentError (LazyString (" invalid argument for Enum " , typename, " : " , s)))
186
187
end
187
188
s = s:: Symbol
188
189
if ! Base. isidentifier (s)
189
- throw (ArgumentError (" invalid name for Enum $ typename ; \" $s \" is not a valid identifier" ))
190
+ throw (ArgumentError (LazyString ( " invalid name for Enum " , typename, " ; \" " , s, " \" is not a valid identifier" ) ))
190
191
end
191
192
if hasexpr && haskey (namemap, i)
192
- throw (ArgumentError (" both $s and $( namemap[i]) have value $i in Enum $ typename ; values must be unique" ))
193
+ throw (ArgumentError (LazyString ( " both " , s, " and " , namemap[i], " have value " , i, " in Enum " , typename, " ; values must be unique" ) ))
193
194
end
194
195
namemap[i] = s
195
196
push! (values, i)
196
197
if s in seen
197
- throw (ArgumentError (" name \" $s \" in Enum $ typename is not unique" ))
198
+ throw (ArgumentError (LazyString ( " name \" " , s, " \" in Enum " , typename, " is not unique" ) ))
198
199
end
199
200
push! (seen, s)
200
201
if length (values) == 1
0 commit comments