Skip to content

Commit 1c45ef6

Browse files
committed
Resolve ambiguities with StaticInt on master
1 parent 6dbee14 commit 1c45ef6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/static.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ StaticInt(::StaticInt{N}) where {N} = StaticInt{N}()
1616
StaticInt(::Val{N}) where {N} = StaticInt{N}()
1717
# Base.Val(::StaticInt{N}) where {N} = Val{N}()
1818
Base.convert(::Type{T}, ::StaticInt{N}) where {T<:Number,N} = convert(T, N)
19+
Base.Bool(x::StaticInt{N}) where {N} = Bool(N)
20+
Base.BigInt(x::StaticInt{N}) where {N} = BigInt(N)
21+
Base.Integer(x::StaticInt{N}) where {N} = x
1922
(::Type{T})(x::StaticInt{N}) where {T<:Integer,N} = T(N)
2023
(::Type{T})(x::Int) where {T<:StaticInt} = StaticInt(x)
2124
Base.convert(::Type{StaticInt{N}}, ::StaticInt{N}) where {N} = StaticInt{N}()

test/runtests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ using OffsetArrays
312312
M = @MArray zeros(2,3,4); Mp = @view(PermutedDimsArray(M,(3,1,2))[:,2,:])';
313313
Sp2 = @view(PermutedDimsArray(S,(3,2,1))[2:3,:,:]);
314314
Mp2 = @view(PermutedDimsArray(M,(3,1,2))[2:3,:,2])';
315-
315+
316316
@test @inferred(ArrayInterface.size(A)) === (3,4,5)
317317
@test @inferred(ArrayInterface.size(Ap)) === (2,5)
318318
@test @inferred(ArrayInterface.size(A)) === size(A)
319319
@test @inferred(ArrayInterface.size(Ap)) === size(Ap)
320-
320+
321321
@test @inferred(ArrayInterface.size(S)) === (StaticInt(2), StaticInt(3), StaticInt(4))
322322
@test @inferred(ArrayInterface.size(Sp)) === (2, 2, StaticInt(3))
323323
@test @inferred(ArrayInterface.size(Sp2)) === (2, StaticInt(3), StaticInt(2))
@@ -430,6 +430,11 @@ end
430430
@test @inferred(one(StaticInt)) === StaticInt(1)
431431
@test @inferred(zero(StaticInt)) === StaticInt(0)
432432
@test eltype(one(StaticInt)) <: Int
433+
434+
x = StaticInt(1)
435+
@test @inferred(Bool(x)) isa Bool
436+
@test @inferred(BigInt(x)) isa BigInt
437+
@test @inferred(Integer(x)) === x
433438
# test for ambiguities and correctness
434439
for i [StaticInt(0), StaticInt(1), StaticInt(2), 3]
435440
for j [StaticInt(0), StaticInt(1), StaticInt(2), 3]

0 commit comments

Comments
 (0)