diff --git a/NEWS.md b/NEWS.md index bd4bd534592ea..b79436318a020 100644 --- a/NEWS.md +++ b/NEWS.md @@ -47,6 +47,7 @@ Language changes used to yield the string " a\nb", since the single space before `b` set the indent level. Now the result is "a\n b", since the space before `b` is no longer considered to occur at the start of a line. The old behavior is considered a bug ([#35001]). +* `<:` and `>:` can now be broadcasted over arrays with `.<:` and `.>:` ([#35085]) * The line number of function definitions is now added by the parser as an additional `LineNumberNode` at the start of each function body ([#35138]). * Statements of the form `a'` now get lowered to `var"'"(a)` instead of `Base.adjoint(a)`. This diff --git a/base/broadcast.jl b/base/broadcast.jl index 509a920e2646b..168431b5566d9 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -1195,6 +1195,9 @@ function __dot__(x::Expr) elseif (x.head === :(=) || x.head === :function || x.head === :macro) && Meta.isexpr(x.args[1], :call) # function or macro definition Expr(x.head, x.args[1], dotargs[2]) + elseif x.head === :(<:) || x.head === :(>:) + tmp = x.head === :(<:) ? :(.<:) : :(.>:) + Expr(:call, tmp, dotargs...) else if x.head === :&& || x.head === :|| error(""" diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 5085eb62ad569..32a1010d8984f 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -15,7 +15,7 @@ (define prec-conditional '(?)) (define prec-arrow (append! '(-- -->) - (add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻)))) + (add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻ <: >:)))) (define prec-lazy-or '(|\|\||)) (define prec-lazy-and '(&&)) (define prec-comparison diff --git a/test/broadcast.jl b/test/broadcast.jl index 2551ee6f4925f..e7bc6df758080 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -923,3 +923,9 @@ k4 = similar(u) f(a,b,c,d,e) = @. a = a + 1*(b+c+d+e) @allocated f(u,k1,k2,k3,k4) @test (@allocated f(u,k1,k2,k3,k4)) == 0 + +ret = @macroexpand @.([Int, Number] <: Real) +@test ret == :([Int, Number] .<: Real) + +ret = @macroexpand @.([Int, Number] >: Real) +@test ret == :([Int, Number] .>: Real) diff --git a/test/parse.jl b/test/parse.jl index 93946b603ba01..89819ec0912ea 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -315,3 +315,14 @@ end @test Meta.parse("±x") == Expr(:call, :±, :x) @test Meta.parse("∓x") == Expr(:call, :∓, :x) end + +@testset "test .<: and .>:" begin + tmp = [Int, Float64, String, Bool] .<: Union{Int, String} + @test tmp == Bool[1, 0, 1, 0] + + tmp = [Int, Float64, String, Bool] .>: [Int, Float64, String, Bool] + @test tmp == Bool[1, 1, 1, 1] + + tmp = @. [Int, Float64, String, Bool] <: Union{Int, String} + @test tmp == Bool[1, 0,1, 0] +end