@@ -547,12 +547,17 @@ class Crystal::Doc::Type
547
547
end
548
548
end
549
549
550
- private def nilable_type_to_html (node , io , links )
550
+ private def nilable_type_to_html (node : ASTNode , io , links )
551
551
node_to_html node, io, links: links
552
552
io << " ?"
553
553
end
554
554
555
- private def nil_type? (node )
555
+ private def nilable_type_to_html (type : Crystal ::Type , io , text , links )
556
+ type_to_html(type , io, text, links: links)
557
+ io << " ?"
558
+ end
559
+
560
+ private def nil_type? (node : ASTNode )
556
561
return false unless node.is_a?(Path )
557
562
558
563
match = lookup_path(node)
@@ -570,6 +575,15 @@ class Crystal::Doc::Type
570
575
571
576
def type_to_html (type : Crystal ::UnionType , io, text = nil , links = true )
572
577
has_type_splat = type .union_types.any? & .is_a?(TypeSplat )
578
+
579
+ if ! has_type_splat && type .union_types.size == 2
580
+ if type .union_types[0 ].nil_type?
581
+ return nilable_type_to_html(type .union_types[1 ], io, text, links)
582
+ elsif type .union_types[1 ].nil_type?
583
+ return nilable_type_to_html(type .union_types[0 ], io, text, links)
584
+ end
585
+ end
586
+
573
587
if has_type_splat
574
588
io << " Union("
575
589
separator = " , "
0 commit comments