Skip to content

Commit ef5457f

Browse files
authored
[Type] correct dict string (#203)
1 parent 0fceb14 commit ef5457f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Psl/Type/Internal/DictType.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function coerce(mixed $value): array
4848
{
4949
if (is_iterable($value)) {
5050
$key_trace = $this->getTrace()
51-
->withFrame(Str\format('array<%s, _>', $this->key_type->toString()));
51+
->withFrame(Str\format('dict<%s, _>', $this->key_type->toString()));
5252
$value_trace = $this->getTrace()
53-
->withFrame(Str\format('array<_, %s>', $this->value_type->toString()));
53+
->withFrame(Str\format('dict<_, %s>', $this->value_type->toString()));
5454

5555
$key_type = $this->key_type->withTrace($key_trace);
5656
$value_type = $this->value_type->withTrace($value_trace);
@@ -82,9 +82,9 @@ public function assert(mixed $value): array
8282
{
8383
if (is_array($value)) {
8484
$key_trace = $this->getTrace()
85-
->withFrame(Str\format('array<%s, _>', $this->key_type->toString()));
85+
->withFrame(Str\format('dict<%s, _>', $this->key_type->toString()));
8686
$value_trace = $this->getTrace()
87-
->withFrame(Str\format('array<_, %s>', $this->value_type->toString()));
87+
->withFrame(Str\format('dict<_, %s>', $this->value_type->toString()));
8888

8989
$key_type = $this->key_type->withTrace($key_trace);
9090
$value_type = $this->value_type->withTrace($value_trace);
@@ -107,6 +107,6 @@ public function assert(mixed $value): array
107107

108108
public function toString(): string
109109
{
110-
return Str\format('array<%s, %s>', $this->key_type->toString(), $this->value_type->toString());
110+
return Str\format('dict<%s, %s>', $this->key_type->toString(), $this->value_type->toString());
111111
}
112112
}

tests/unit/Type/DictTypeTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public function getInvalidCoercions(): iterable
9191

9292
public function getToStringExamples(): iterable
9393
{
94-
yield [$this->getType(), 'array<int, int>'];
95-
yield [Type\dict(Type\array_key(), Type\int()), 'array<array-key, int>'];
96-
yield [Type\dict(Type\array_key(), Type\string()), 'array<array-key, string>'];
94+
yield [$this->getType(), 'dict<int, int>'];
95+
yield [Type\dict(Type\array_key(), Type\int()), 'dict<array-key, int>'];
96+
yield [Type\dict(Type\array_key(), Type\string()), 'dict<array-key, string>'];
9797
yield [
9898
Type\dict(Type\array_key(), Type\object(Iter\Iterator::class)),
99-
'array<array-key, Psl\Iter\Iterator>'
99+
'dict<array-key, Psl\Iter\Iterator>'
100100
];
101101
}
102102
}

0 commit comments

Comments
 (0)