Skip to content

Commit 9314ccf

Browse files
committed
Correct keyed array printing (fix #8)
1 parent d11a4f7 commit 9314ccf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ShowTypePrettier.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ private static function keyedArray(Atomic\TKeyedArray $atomic, Codebase $codebas
165165

166166
$openBracket = 'array{';
167167
$closeBracket = $level === 1 ? '}' : $tab($level - 1) . '}';
168+
$isList = self::isKeyedArrayList($atomic);
168169

169-
$shape = $atomic->is_list
170+
$shape = $isList
170171
? array_map(
171172
fn(Union $type) => self::union($type, $codebase, $level + 1),
172173
$atomic->properties,
@@ -181,8 +182,13 @@ private static function keyedArray(Atomic\TKeyedArray $atomic, Codebase $codebas
181182
array_values($atomic->properties),
182183
);
183184

184-
return $atomic->is_list
185+
return $isList
185186
? $openBracket . implode(", ", array_values($shape)) . $closeBracket
186187
: $openBracket . "\n" . implode(",\n", array_values($shape)) . ",\n" . $closeBracket;
187188
}
189+
190+
private static function isKeyedArrayList(Atomic\TKeyedArray $atomic): bool
191+
{
192+
return array_keys($atomic->properties) === range(0, count($atomic->properties) - 1);
193+
}
188194
}

0 commit comments

Comments
 (0)