9090# give Enum types scalar behavior in broadcasting
9191Base. broadcastable (x:: Enum ) = Ref (x)
9292
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 )))
9494
9595"""
9696 @enum EnumName[::BaseType] value1[=x] value2[=y]
@@ -143,18 +143,19 @@ julia> Symbol(apple)
143143"""
144144macro enum (T:: Union{Symbol,Expr} , syms... )
145145 if isempty (syms)
146- throw (ArgumentError (" no arguments given for Enum $T " ))
146+ throw (ArgumentError (LazyString ( " no arguments given for Enum " , T) ))
147147 end
148148 basetype = Int32
149149 typename = T
150150 if isa (T, Expr) && T. head === :(:: ) && length (T. args) == 2 && isa (T. args[1 ], Symbol)
151151 typename = T. args[1 ]
152152 basetype = Core. eval (__module__, T. args[2 ])
153153 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" )))
155156 end
156157 elseif ! isa (T, Symbol)
157- throw (ArgumentError (" invalid type expression for enum $T " ))
158+ throw (ArgumentError (LazyString ( " invalid type expression for enum " , T) ))
158159 end
159160 values = Vector {basetype} ()
160161 seen = Set {Symbol} ()
@@ -169,32 +170,32 @@ macro enum(T::Union{Symbol,Expr}, syms...)
169170 s isa LineNumberNode && continue
170171 if isa (s, Symbol)
171172 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) ))
173174 end
174175 elseif isa (s, Expr) &&
175176 (s. head === :(= ) || s. head === :kw ) &&
176177 length (s. args) == 2 && isa (s. args[1 ], Symbol)
177178 i = Core. eval (__module__, s. args[2 ]) # allow exprs, e.g. uint128"1"
178179 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" ) ))
180181 end
181182 i = convert (basetype, i)
182183 s = s. args[1 ]
183184 hasexpr = true
184185 else
185- throw (ArgumentError (string (" invalid argument for Enum " , typename, " : " , s)))
186+ throw (ArgumentError (LazyString (" invalid argument for Enum " , typename, " : " , s)))
186187 end
187188 s = s:: Symbol
188189 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" ) ))
190191 end
191192 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" ) ))
193194 end
194195 namemap[i] = s
195196 push! (values, i)
196197 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" ) ))
198199 end
199200 push! (seen, s)
200201 if length (values) == 1
0 commit comments