File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,11 @@ base_numeric_type(x) = base_numeric_type(typeof(x))
3030
3131function _base_numeric_type (:: Type{T} ) where {T}
3232 params = T isa UnionAll ? T. body. parameters : T. parameters
33- return isempty (params) ? T : _base_numeric_type (first (params))
34- # TODO : deal with recursive types
33+ if isempty (params)
34+ return T
35+ else
36+ return _base_numeric_type (first (params))
37+ end
3538end
3639
3740end
Original file line number Diff line number Diff line change 11using Test: @test , @testset , @inferred
22using BaseType: base_numeric_type
3- using DualNumbers: DualNumbers
3+ using DualNumbers: DualNumbers, Dual
44using DynamicQuantities: DynamicQuantities
55using Measurements: ±
66using Unitful: Unitful
3737 y = Dual (1.0 )Unitful. u " m/s"
3838 @test base_numeric_type (y) == Float64
3939end
40+
41+ struct Node{T}
42+ child:: Union{Node{T},Nothing}
43+ value:: T
44+ end
45+
46+ @testset " Safe default behavior for recursive types" begin
47+ c = Node {Int} (Node {Int} (nothing , 1 ), 2 )
48+ @test base_numeric_type (c) == Int
49+ end
You can’t perform that action at this time.
0 commit comments