Skip to content

Commit

Permalink
Check Type has parameters field with an element
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentrik committed Sep 1, 2023
1 parent a017a4d commit 5cd1923
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TypedSyntax/src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function type_annotation_mode(node, @nospecialize(T); type_annotations::Bool, hi
type_annotate = is_show_annotation(T; type_annotations, hide_type_stable)
pre = pre2 = post = ""
if type_annotate
if T isa Type && T <: Type
if T isa Type && T <: Type && T !== Union{} && isassigned(T.parameters, 1)
# Don't annotate `String::Type{String}`
if replace(sourcetext(node), r"\s" => "") == replace(sprint(show, T.parameters[1]), r"\s" => "")
return false, pre, pre2, post
Expand Down
10 changes: 10 additions & 0 deletions TypedSyntax/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,16 @@ include("test_module.jl")
@test_nowarn str = sprint(tsn; context=:color=>false) do io, obj
printstyled(io, obj; hide_type_stable=false)
end

# issue 491
tsn = TypedSyntaxNode(+, (Int, Int)) # need a node, not important what it is
@test_nowarn TypedSyntax.type_annotation_mode(tsn, Union{}; type_annotations=true, hide_type_stable=false)

# issue 492
tsn = TypedSyntaxNode(Base._tuple_unique_fieldtypes, (Any,))
@test_nowarn str = sprint(tsn; context=:color=>false) do io, obj
printstyled(io, obj; hide_type_stable=false)
end
end

if parse(Bool, get(ENV, "CI", "false"))
Expand Down

0 comments on commit 5cd1923

Please sign in to comment.