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))
30
30
31
31
function _base_numeric_type (:: Type{T} ) where {T}
32
32
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
35
38
end
36
39
37
40
end
Original file line number Diff line number Diff line change 1
1
using Test: @test , @testset , @inferred
2
2
using BaseType: base_numeric_type
3
- using DualNumbers: DualNumbers
3
+ using DualNumbers: DualNumbers, Dual
4
4
using DynamicQuantities: DynamicQuantities
5
5
using Measurements: ±
6
6
using Unitful: Unitful
37
37
y = Dual (1.0 )Unitful. u " m/s"
38
38
@test base_numeric_type (y) == Float64
39
39
end
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