• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37477

pending completion
#37477

push

local

web-flow
Allow external lattice elements to properly union split (#49030)

Currently `MustAlias` is the only lattice element that is allowed
to widen to union types. However, there are others in external
packages. Expand the support we have for this in order to allow
union splitting of lattice elements.

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

26 of 26 new or added lines in 5 files covered. (100.0%)

71476 of 82705 relevant lines covered (86.42%)

34756248.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.78
/stdlib/Dates/src/ranges.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# Date/DateTime Ranges
4

5
StepRange{<:Dates.DatePeriod,<:Real}(start, step, stop) =
×
6
    throw(ArgumentError("must specify step as a Period when constructing Dates ranges"))
7
Base.:(:)(a::T, b::T) where {T<:Date} = (:)(a, Day(1), b)
1✔
8

9
# Given a start and end date, how many steps/periods are in between
10
guess(a::DateTime, b::DateTime, c) = floor(Int64, (Int128(value(b)) - Int128(value(a))) / toms(c))
46,213✔
11
guess(a::Date, b::Date, c) = Int64(div(value(b - a), days(c)))
443,900✔
12
len(a::Time, b::Time, c) = Int64(div(value(b - a), tons(c)))
149✔
13
function len(a, b, c)
490,113✔
14
    lo, hi, st = min(a, b), max(a, b), abs(c)
490,113✔
15
    i = guess(a, b, c)
490,113✔
16
    v = lo + st * i
490,113✔
17
    prev = v  # Ensure `v` does not overflow
490,113✔
18
    while v <= hi && prev <= v
527,241,539✔
19
        prev = v
526,751,426✔
20
        v += st
526,751,426✔
21
        i += 1
526,751,426✔
22
    end
526,751,426✔
23
    return i - 1
490,113✔
24
end
25
Base.length(r::StepRange{<:TimeType}) = isempty(r) ? Int64(0) : len(r.start, r.stop, r.step) + 1
496,643✔
26
# Period ranges hook into Int64 overflow detection
27
Base.length(r::StepRange{<:Period}) = length(StepRange(value(r.start), value(r.step), value(r.stop)))
4✔
28
Base.checked_length(r::StepRange{<:Period}) = Base.checked_length(StepRange(value(r.start), value(r.step), value(r.stop)))
×
29

30
# Overload Base.steprange_last because `step::Period` may be a variable amount of time (e.g. for Month and Year)
31
function Base.steprange_last(start::T, step, stop) where T<:TimeType
242,621✔
32
    if isa(step, AbstractFloat)
242,621✔
33
        throw(ArgumentError("StepRange should not be used with floating point"))
×
34
    end
35
    z = zero(step)
242,621✔
36
    step == z && throw(ArgumentError("step cannot be zero"))
242,621✔
37

38
    if stop == start
242,621✔
39
        last = stop
539✔
40
    else
41
        if (step > z) != (stop > start)
242,082✔
42
            last = Base.steprange_last_empty(start, step, stop)
714✔
43
        else
44
            diff = stop - start
241,368✔
45
            if (diff > zero(diff)) != (stop > start)
241,368✔
46
                throw(OverflowError("Difference between stop and start overflowed"))
1✔
47
            end
48
            remain = stop - (start + step * len(start, stop, step))
241,367✔
49
            last = stop - remain
241,367✔
50
        end
51
    end
52
    return last
242,620✔
53
end
54

55
import Base.in
56
function in(x::T, r::StepRange{T}) where T<:TimeType
1,005✔
57
    n = len(first(r), x, step(r)) + 1
1,005✔
58
    n >= 1 && n <= length(r) && r[n] == x
1,005✔
59
end
60

61
Base.iterate(r::StepRange{<:TimeType}) = length(r) <= 0 ? nothing : (r.start, (length(r), 1))
3,013✔
62
Base.iterate(r::StepRange{<:TimeType}, (l, i)) = l <= i ? nothing : (r.start + r.step * i, (l, i + 1))
986,528✔
63

64
+(x::Period, r::AbstractRange{<:TimeType}) = (x + first(r)):step(r):(x + last(r))
1✔
65
+(r::AbstractRange{<:TimeType}, x::Period) = x + r
1✔
66
-(r::AbstractRange{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x)
1✔
67
*(x::Period, r::AbstractRange{<:Real}) = (x * first(r)):(x * step(r)):(x * last(r))
×
68
*(r::AbstractRange{<:Real}, x::Period) = x * r
×
69
/(r::AbstractRange{<:P}, x::P) where {P<:Period} = (first(r)/x):(step(r)/x):(last(r)/x)
×
70

71
# Combinations of types and periods for which the range step is regular
72
Base.RangeStepStyle(::Type{<:OrdinalRange{<:TimeType, <:FixedPeriod}}) =
×
73
    Base.RangeStepRegular()
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc