Skip to content

Commit 2e57730

Browse files
authored
lowering: Allow chaining of >: in where (#57554)
This change removes an inconsistency between `>:` and `<:`. We were parsing `where {A>:B>:C}` forms, but not recognizing them in lowering. Before: ``` julia> Vector{T} where Int<:T<:Number Vector{T} where Int64<:T<:Number julia> Vector{T} where Number>:T>:Int ERROR: syntax: invalid bounds in "where" around REPL[14]:1 ``` After: ``` julia> Vector{T} where Number>:T>:Int Vector{T} where Int64<:T<:Number ```
1 parent b0323ab commit 2e57730

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/julia-syntax.scm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,14 @@
194194
(cond ((atom? e) (list (check-sym e) #f #f))
195195
((eq? (car e) 'var-bounds) (cdr e))
196196
((and (eq? (car e) 'comparison) (length= e 6))
197-
(cons (check-sym (cadddr e))
198-
(cond ((and (eq? (caddr e) '|<:|) (eq? (caddr (cddr e)) '|<:|))
199-
(list (cadr e) (last e)))
200-
(else (error "invalid bounds in \"where\"")))))
197+
(let* ((lhs (list-ref e 1))
198+
(rel (list-ref e 2))
199+
(t (check-sym (list-ref e 3)))
200+
(rel-same (eq? rel (list-ref e 4)))
201+
(rhs (list-ref e 5)))
202+
(cond ((and rel-same (eq? rel '|<:|)) (list t lhs rhs))
203+
((and rel-same (eq? rel '|>:|)) (list t rhs lhs))
204+
(else (error "invalid bounds in \"where\"")))))
201205
((eq? (car e) '|<:|)
202206
(list (check-sym (cadr e)) #f (caddr e)))
203207
((eq? (car e) '|>:|)

test/syntax.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,10 @@ let args = (Int, Any)
12961296
@test >:(reverse(args)...)
12971297
end
12981298

1299+
# Chaining of <: and >: in `where`
1300+
@test isa(Vector{T} where Int<:T<:Number, UnionAll)
1301+
@test isa(Vector{T} where Number>:T>:Int, UnionAll)
1302+
12991303
# issue #25947
13001304
let getindex = 0, setindex! = 1, colon = 2, vcat = 3, hcat = 4, hvcat = 5
13011305
a = [10,9,8]

0 commit comments

Comments
 (0)