From 04bad437c7568a17051bbcf1f76ea943e517ca0a Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 25 Oct 2023 08:04:13 +0200 Subject: [PATCH] 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. --- src/ast/printing.jl | 11 ++++++++++- test/runtests.jl | 1 + test/vararg.jl | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/vararg.jl diff --git a/src/ast/printing.jl b/src/ast/printing.jl index eecc880..c0da0c7 100644 --- a/src/ast/printing.jl +++ b/src/ast/printing.jl @@ -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" + 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) diff --git a/test/runtests.jl b/test/runtests.jl index 530e6d2..c387a1f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,6 +23,7 @@ end include("frontend/cast.jl") include("frontend/markdown.jl") include("long_print.jl") + include("vararg.jl") end @testset "codegen" begin diff --git a/test/vararg.jl b/test/vararg.jl new file mode 100644 index 0000000..6e6c249 --- /dev/null +++ b/test/vararg.jl @@ -0,0 +1,2 @@ +using Comonicon +@main foo(xs::Vararg{String}) = foreach(println, xs)