Skip to content

Commit 99dbd2d

Browse files
authored
add <: to add-dots (#35085)
1 parent 816df51 commit 99dbd2d

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Language changes
4747
used to yield the string " a\nb", since the single space before `b` set the indent level.
4848
Now the result is "a\n b", since the space before `b` is no longer considered to occur
4949
at the start of a line. The old behavior is considered a bug ([#35001]).
50+
* `<:` and `>:` can now be broadcasted over arrays with `.<:` and `.>:` ([#35085])
5051
* The line number of function definitions is now added by the parser as an
5152
additional `LineNumberNode` at the start of each function body ([#35138]).
5253
* Statements of the form `a'` now get lowered to `var"'"(a)` instead of `Base.adjoint(a)`. This

base/broadcast.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,9 @@ function __dot__(x::Expr)
11951195
elseif (x.head === :(=) || x.head === :function || x.head === :macro) &&
11961196
Meta.isexpr(x.args[1], :call) # function or macro definition
11971197
Expr(x.head, x.args[1], dotargs[2])
1198+
elseif x.head === :(<:) || x.head === :(>:)
1199+
tmp = x.head === :(<:) ? :(.<:) : :(.>:)
1200+
Expr(:call, tmp, dotargs...)
11981201
else
11991202
if x.head === :&& || x.head === :||
12001203
error("""

src/julia-parser.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(define prec-conditional '(?))
1616
(define prec-arrow (append!
1717
'(-- -->)
18-
(add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻))))
18+
(add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻ <: >:))))
1919
(define prec-lazy-or '(|\|\||))
2020
(define prec-lazy-and '(&&))
2121
(define prec-comparison

test/broadcast.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,9 @@ k4 = similar(u)
923923
f(a,b,c,d,e) = @. a = a + 1*(b+c+d+e)
924924
@allocated f(u,k1,k2,k3,k4)
925925
@test (@allocated f(u,k1,k2,k3,k4)) == 0
926+
927+
ret = @macroexpand @.([Int, Number] <: Real)
928+
@test ret == :([Int, Number] .<: Real)
929+
930+
ret = @macroexpand @.([Int, Number] >: Real)
931+
@test ret == :([Int, Number] .>: Real)

test/parse.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,14 @@ end
315315
@test Meta.parse("±x") == Expr(:call, :±, :x)
316316
@test Meta.parse("∓x") == Expr(:call, :, :x)
317317
end
318+
319+
@testset "test .<: and .>:" begin
320+
tmp = [Int, Float64, String, Bool] .<: Union{Int, String}
321+
@test tmp == Bool[1, 0, 1, 0]
322+
323+
tmp = [Int, Float64, String, Bool] .>: [Int, Float64, String, Bool]
324+
@test tmp == Bool[1, 1, 1, 1]
325+
326+
tmp = @. [Int, Float64, String, Bool] <: Union{Int, String}
327+
@test tmp == Bool[1, 0,1, 0]
328+
end

0 commit comments

Comments
 (0)