Skip to content

Commit

Permalink
Fix printing of Vararg on Julia 1.7
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakobnissen committed Oct 25, 2023
1 parent afd7e15 commit 04bad43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ast/printing.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
tab(n::Int) = " "^n
ignore_type(type) = type in [Any, String] || type <: AbstractString

function is_vararg(T)
@static if VERSION < v"1.7"

Check warning on line 4 in src/ast/printing.jl

View check run for this annotation

Codecov / codecov/patch

src/ast/printing.jl#L4

Added line #L4 was not covered by tests
T <: Vararg
else
typeof(T) == Core.TypeofVararg
end
end

ignore_type(type) = !is_vararg(type) && (type in [Any, String] || type <: AbstractString)

function has_args(cmd::LeafCommand)
!isempty(cmd.args) || !isnothing(cmd.vararg)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end
include("frontend/cast.jl")
include("frontend/markdown.jl")
include("long_print.jl")
include("vararg.jl")
end

@testset "codegen" begin
Expand Down
2 changes: 2 additions & 0 deletions test/vararg.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
using Comonicon
@main foo(xs::Vararg{String}) = foreach(println, xs)

0 comments on commit 04bad43

Please sign in to comment.