@@ -201,18 +201,18 @@ function generate_constructor_exprs(T_name, T_params, T_params_constrained, T_na
201201 end
202202 if true
203203 push! (converts, T_uninit => quote
204- $ Base. convert (:: $Type{<:$T_init} , $ x:: $T_uninit ) where {$ (T_params ... )} = $ if_nest_conv
205- (:: $Type{<:$T_init} )($ x:: $T_uninit ) where {$ (T_params ... )} = $ if_nest_conv
206- $ Base. convert (:: $Type{$T_init} , $ x:: $T_uninit{$N, $M, $FT} ) where {$ (T_params ... ), $ N, $ M, $ FT} = $ if_nest_conv
207- (:: $Type{$T_init} )($ x:: $T_uninit ) where {$ (T_params ... )} = $ if_nest_conv
204+ $ Base. convert (:: $Type{<:$T_init} , $ x:: $T_uninit ) where {$ (T_params_constrained ... )} = $ if_nest_conv
205+ (:: $Type{<:$T_init} )($ x:: $T_uninit ) where {$ (T_params_constrained ... )} = $ if_nest_conv
206+ $ Base. convert (:: $Type{$T_init} , $ x:: $T_uninit{$N, $M, $FT} ) where {$ (T_params_constrained ... ), $ N, $ M, $ FT} = $ if_nest_conv
207+ (:: $Type{$T_init} )($ x:: $T_uninit ) where {$ (T_params_constrained ... )} = $ if_nest_conv
208208 end )
209209 end
210210 end
211211 unique! (x -> x[1 ], converts)
212212 append! (out. args, map (x -> x[2 ], converts))
213213 push! (out. args, quote
214- $ Base. convert (:: $Type{$_T} , $ x:: $_T ) where {$ (T_params ... ), $ _T <: $T_nameparam } = $ x
215- (:: $Type{$_T} )($ x:: $_T ) where {$ (T_params ... ), $ _T <: $T_nameparam } = $ x
214+ $ Base. convert (:: $Type{$_T} , $ x:: $_T ) where {$ (T_params_constrained ... ), $ _T <: $T_nameparam } = $ x
215+ (:: $Type{$_T} )($ x:: $_T ) where {$ (T_params_constrained ... ), $ _T <: $T_nameparam } = $ x
216216 end )
217217 out
218218end
@@ -242,12 +242,12 @@ function generate_sum_struct_expr(T, T_name, T_params, T_params_constrained, T_p
242242 only_define_with_params = if ! isempty (T_params)
243243 @gensym x
244244 quote
245- $ SumTypes. constructors (:: Type{<:$T_nameparam} ) where {$ (T_params ... )} =
245+ $ SumTypes. constructors (:: Type{<:$T_nameparam} ) where {$ (T_params_constrained ... )} =
246246 $ NamedTuple {$tags($T_name)} ($ (Expr (:tuple , (nt. store_type for nt ∈ constructors). .. )))
247- $ Base. adjoint (:: Type{<:$T_nameparam} ) where {$ (T_params ... )} =
247+ $ Base. adjoint (:: Type{<:$T_nameparam} ) where {$ (T_params_constrained ... )} =
248248 $ NamedTuple {$tags($T_name)} ($ (Expr (:tuple , (nt. value ? :($ T_nameparam ($ (nt. gname))) : :($ Converter {$T_nameparam, $(nt.gouter_type)} ())
249249 for nt ∈ constructors). .. )))
250- $ SumTypes. variants_Tuple (:: Type{<:$T_nameparam} ) where {$ (T_params ... )} =
250+ $ SumTypes. variants_Tuple (:: Type{<:$T_nameparam} ) where {$ (T_params_constrained ... )} =
251251 $ Tuple{$ ((nt. store_type for nt ∈ constructors). .. )}
252252 $ SumTypes. full_type (:: Type{$T_name} ) = $ full_type ($ T_name{$ (T_param_bounds... )}, $ variants_Tuple ($ T_name{$ (T_param_bounds... )}))
253253 end
@@ -259,9 +259,9 @@ function generate_sum_struct_expr(T, T_name, T_params, T_params_constrained, T_p
259259 ex = quote
260260 $ sum_struct_def
261261 $ SumTypes. is_sumtype (:: Type{<:$T_name} ) = true
262- $ SumTypes. strip_size_params (:: Type{$T_name{$(T_params...), $N, $M, $FT}} ) where {$ (T_params ... ), $ N, $ M, $ FT} = $ T_nameparam
262+ $ SumTypes. strip_size_params (:: Type{$T_name{$(T_params...), $N, $M, $FT}} ) where {$ (T_params_constrained ... ), $ N, $ M, $ FT} = $ T_nameparam
263263 $ SumTypes. flagtype (:: Type{$_T} ) where {$ _T <: $T_name } = $ flagtype ($ full_type ($ _T))
264- $ SumTypes. flagtype (:: Type{$T_name{$(T_params...), $N, $M, $FT}} ) where {$ (T_params ... ), $ N, $ M, $ FT} = $ FT
264+ $ SumTypes. flagtype (:: Type{$T_name{$(T_params...), $N, $M, $FT}} ) where {$ (T_params_constrained ... ), $ N, $ M, $ FT} = $ FT
265265
266266 $ SumTypes. symbol_to_flag (:: Type{$_T} , sym:: Symbol ) where {$ _T <: $T_name } =
267267 $ (foldr (collect (enumerate (con_names)), init= :(error (" Invalid tag symbol $sym " ))) do (i, _sym), old
@@ -281,14 +281,14 @@ function generate_sum_struct_expr(T, T_name, T_params, T_params_constrained, T_p
281281 $ SumTypes. variants_Tuple (:: Type{<:$T_name} ) =
282282 $ Tuple{$ ((nt. store_type_uninit for nt ∈ constructors). .. )}
283283
284- $ SumTypes. unwrap (x:: $T_nameparam{$N, $M, $FT} ) where {$ (T_params ... ), $ N, $ M, $ FT}= let tag = $ get_tag (x)
284+ $ SumTypes. unwrap (x:: $T_nameparam{$N, $M, $FT} ) where {$ (T_params_constrained ... ), $ N, $ M, $ FT}= let tag = $ get_tag (x)
285285 $ if_nest_unwrap
286286 end
287287 $ Base. adjoint (:: Type{<:$T_name} ) =
288288 $ NamedTuple {$tags($T_name)} ($ (Expr (:tuple , (nt. gname for nt ∈ constructors). .. )))
289289
290- $ SumTypes. full_type (:: Type{$T_nameparam} ) where {$ (T_params ... )} = $ full_type ($ T_nameparam, $ variants_Tuple ($ T_nameparam))
291- $ SumTypes. full_type (:: Type{$T_nameparam{$N, $M, $FT}} ) where {$ (T_params ... ), $ N, $ M, $ FT} = $ T_nameparam{$ N, $ M, $ FT}
290+ $ SumTypes. full_type (:: Type{$T_nameparam} ) where {$ (T_params_constrained ... )} = $ full_type ($ T_nameparam, $ variants_Tuple ($ T_nameparam))
291+ $ SumTypes. full_type (:: Type{$T_nameparam{$N, $M, $FT}} ) where {$ (T_params_constrained ... ), $ N, $ M, $ FT} = $ T_nameparam{$ N, $ M, $ FT}
292292
293293 $ Base. show (io:: IO , x:: $T_name ) = $ show_sumtype (io, x)
294294 $ Base. show (io:: IO , m:: MIME"text/plain" , x:: $T_name ) = $ show_sumtype (io, m, x)
@@ -299,9 +299,10 @@ function generate_sum_struct_expr(T, T_name, T_params, T_params_constrained, T_p
299299 foreach (constructors) do nt
300300 con1 = :($ SumTypes. constructor (:: Type{<:$T_name} , :: Type{Val{$(QuoteNode(nt.name))}} ) = $ (nt. store_type_uninit))
301301 con2 = if ! isempty (T_params)
302- :($ SumTypes. constructor (:: Type{<:$T_nameparam} , :: Type{Val{$(QuoteNode(nt.name))}} ) where {$ (T_params ... )} = $ (nt. store_type))
302+ :($ SumTypes. constructor (:: Type{<:$T_nameparam} , :: Type{Val{$(QuoteNode(nt.name))}} ) where {$ (T_params_constrained ... )} = $ (nt. store_type))
303303 end
304304 push! (ex. args, con1, con2)
305305 end
306306 ex
307307end
308+
0 commit comments