@@ -332,22 +332,48 @@ enumerated types (see `@enum`).
332
332
function instances end
333
333
334
334
# subtypes
335
- function _subtypes (m:: Module , x:: DataType , sts= Set {DataType} (), visited= Set {Module} ())
335
+ function _subtypes (m:: Module , x:: Union{DataType,UnionAll} ,
336
+ sts= Set {Union{DataType,UnionAll}} (), visited= Set {Module} ())
336
337
push! (visited, m)
338
+ xt = unwrap_unionall (x)
339
+ if ! isa (xt, DataType)
340
+ return sts
341
+ end
342
+ xt = xt:: DataType
337
343
for s in names (m, true )
338
344
if isdefined (m, s) && ! isdeprecated (m, s)
339
345
t = getfield (m, s)
340
- if isa (t, DataType) && t. name. name == s && supertype (t). name == x. name
341
- ti = typeintersect (t, x)
342
- ti != Bottom && push! (sts, ti)
343
- elseif isa (t, Module) && ! in (t, visited)
344
- _subtypes (t, x, sts, visited)
346
+ if isa (t, DataType)
347
+ t = t:: DataType
348
+ if t. name. name === s && supertype (t). name == xt. name
349
+ ti = typeintersect (t, x)
350
+ ti != Bottom && push! (sts, ti)
351
+ end
352
+ elseif isa (t, UnionAll)
353
+ t = t:: UnionAll
354
+ tt = unwrap_unionall (t)
355
+ isa (tt, DataType) || continue
356
+ tt = tt:: DataType
357
+ if tt. name. name === s && supertype (tt). name == xt. name
358
+ ti = typeintersect (t, x)
359
+ ti != Bottom && push! (sts, ti)
360
+ end
361
+ elseif isa (t, Module)
362
+ t = t:: Module
363
+ in (t, visited) || _subtypes (t, x, sts, visited)
345
364
end
346
365
end
347
366
end
348
367
return sts
349
368
end
350
- subtypes (m:: Module , x:: DataType ) = x. abstract ? sort! (collect (_subtypes (m, x)), by= string) : DataType[]
369
+ function subtypes (m:: Module , x:: Union{DataType,UnionAll} )
370
+ if isabstract (x)
371
+ sort! (collect (_subtypes (m, x)), by= string)
372
+ else
373
+ # Fast path
374
+ Union{DataType,UnionAll}[]
375
+ end
376
+ end
351
377
352
378
"""
353
379
subtypes(T::DataType)
@@ -364,7 +390,7 @@ julia> subtypes(Integer)
364
390
Unsigned
365
391
```
366
392
"""
367
- subtypes (x:: DataType ) = subtypes (Main, x)
393
+ subtypes (x:: Union{ DataType,UnionAll} ) = subtypes (Main, x)
368
394
369
395
function to_tuple_type (t:: ANY )
370
396
@_pure_meta
0 commit comments