Skip to content

Commit 1fbd7ea

Browse files
committed
Improve AT constraint indication when dumping type to string
1 parent 074a3dc commit 1fbd7ea

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Zend/tests/type_declarations/associated/associated_type_with_constraint_failed.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ class C implements I {
1414

1515
?>
1616
--EXPECTF--
17-
Fatal error: Declaration of C::foo(float $param): float must be compatible with I::foo(T<string|int> $param): T<string|int> in %s on line %d
17+
Fatal error: Declaration of C::foo(float $param): float must be compatible with I::foo(<T : string|int> $param): <T : string|int> in %s on line %d

Zend/tests/type_declarations/associated/big_example.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ final class StringTable
9999

100100
?>
101101
--EXPECTF--
102-
Fatal error: Declaration of Sequence\StringTableSequence::next(): ?Sequence\StringTablePair must be compatible with Sequence\Sequence::next(): Item<object|array|string|int|float|bool>|null in %s on line %d
102+
Fatal error: Declaration of Sequence\StringTableSequence::next(): ?Sequence\StringTablePair must be compatible with Sequence\Sequence::next(): <Item : object|array|string|int|float|bool>|null in %s on line %d

Zend/tests/type_declarations/associated/extended_interface_new_associated_types.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class C implements I2 {
1919
}
2020

2121
// TODO: Ideally error message would be:
22-
//Fatal error: Declaration of C::bar(float $o, string $param): float must be compatible with I2::bar(T2<stdClass|float|bool> $o, T<(Traversable&Countable)|int|string> $param): T2<stdClass|float|bool> in %s on line %d
22+
//Fatal error: Declaration of C::bar(float $o, string $param): float must be compatible with I2::bar(<T2 : stdClass|float|bool> $o, <T : (Traversable&Countable)|int|string> $param): <T2 : stdClass|float|bool> in %s on line %d
2323
//Improve zend_append_type_hint()?
2424
?>
2525
--EXPECTF--
26-
Fatal error: Declaration of C::bar(float $o, string $param): float must be compatible with I2::bar(T2<stdClass|float|bool> $o, T $param): T2<stdClass|float|bool> in %s on line %d
26+
Fatal error: Declaration of C::bar(float $o, string $param): float must be compatible with I2::bar(<T2 : stdClass|float|bool> $o, T $param): <T2 : stdClass|float|bool> in %s on line %d

Zend/zend_compile.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,15 @@ static zend_string *add_associated_type(zend_string *associated_type, zend_class
14481448

14491449
zend_string *constraint_type_str = zend_type_to_string_resolved(*constraint, scope);
14501450

1451-
size_t len = ZSTR_LEN(associated_type) + ZSTR_LEN(constraint_type_str) + strlen("<>");
1451+
size_t len = ZSTR_LEN(associated_type) + ZSTR_LEN(constraint_type_str) + strlen("< : >");
14521452
zend_string *result = zend_string_alloc(len, 0);
14531453

1454-
memcpy(ZSTR_VAL(result), ZSTR_VAL(associated_type), ZSTR_LEN(associated_type));
1455-
ZSTR_VAL(result)[ZSTR_LEN(associated_type)] = '<';
1456-
memcpy(ZSTR_VAL(result) + ZSTR_LEN(associated_type) + 1, ZSTR_VAL(constraint_type_str), ZSTR_LEN(constraint_type_str));
1454+
ZSTR_VAL(result)[0] = '<';
1455+
memcpy(ZSTR_VAL(result) + strlen("<"), ZSTR_VAL(associated_type), ZSTR_LEN(associated_type));
1456+
ZSTR_VAL(result)[ZSTR_LEN(associated_type) + 1] = ' ';
1457+
ZSTR_VAL(result)[ZSTR_LEN(associated_type) + 2] = ':';
1458+
ZSTR_VAL(result)[ZSTR_LEN(associated_type) + 3] = ' ';
1459+
memcpy(ZSTR_VAL(result) + ZSTR_LEN(associated_type) + strlen("< : "), ZSTR_VAL(constraint_type_str), ZSTR_LEN(constraint_type_str));
14571460
ZSTR_VAL(result)[len-1] = '>';
14581461
ZSTR_VAL(result)[len] = '\0';
14591462

0 commit comments

Comments
 (0)