Skip to content

Commit 04bad43

Browse files
committed
Fix printing of Vararg on Julia 1.7
Recent versions of Julia has moved Vararg from being a Type to being its own thing. This means it will error if T is a vararg and you try to do `isa` to `<:` operations with it. This caused an error, which is fixed here by explicitly testing if T is a Vararg.
1 parent afd7e15 commit 04bad43

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/ast/printing.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
tab(n::Int) = " "^n
2-
ignore_type(type) = type in [Any, String] || type <: AbstractString
2+
3+
function is_vararg(T)
4+
@static if VERSION < v"1.7"
5+
T <: Vararg
6+
else
7+
typeof(T) == Core.TypeofVararg
8+
end
9+
end
10+
11+
ignore_type(type) = !is_vararg(type) && (type in [Any, String] || type <: AbstractString)
312

413
function has_args(cmd::LeafCommand)
514
!isempty(cmd.args) || !isnothing(cmd.vararg)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ end
2323
include("frontend/cast.jl")
2424
include("frontend/markdown.jl")
2525
include("long_print.jl")
26+
include("vararg.jl")
2627
end
2728

2829
@testset "codegen" begin

test/vararg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
using Comonicon
2+
@main foo(xs::Vararg{String}) = foreach(println, xs)

0 commit comments

Comments
 (0)