Skip to content

Commit de5f6a8

Browse files
committed
Improve wording of redudant intersection types in unions
1 parent 0653ef7 commit de5f6a8

5 files changed

+20
-23
lines changed

Zend/tests/type_declarations/dnf_types/redundant_types/less_restrive_type_constraint_already_present001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function test(): (A&B)|A {}
1111
?>
1212
===DONE===
1313
--EXPECTF--
14-
Fatal error: Type A is less restrictive than type A&B in %s on line %d
14+
Fatal error: Type A&B is redundant as it is more restrictive than type A in %s on line %d

Zend/tests/type_declarations/dnf_types/redundant_types/less_restrive_type_constraint_already_present002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function test(): A|(A&B) {}
1111
?>
1212
===DONE===
1313
--EXPECTF--
14-
Fatal error: Type A is less restrictive than type A&B in %s on line %d
14+
Fatal error: Type A&B is redundant as it is more restrictive than type A in %s on line %d

Zend/tests/type_declarations/dnf_types/redundant_types/less_restrive_type_constraint_already_present003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ function test(): (A&B)|(A&B&C) {}
1212
?>
1313
===DONE===
1414
--EXPECTF--
15-
Fatal error: Type A&B is less restrictive than type A&B&C in %s on line %d
15+
Fatal error: Type A&B&C is redundant as it is more restrictive than type A&B in %s on line %d

Zend/tests/type_declarations/dnf_types/redundant_types/less_restrive_type_constraint_already_present004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ function test(): (A&B&C)|(A&B) {}
1212
?>
1313
===DONE===
1414
--EXPECTF--
15-
Fatal error: Type A&B is less restrictive than type A&B&C in %s on line %d
15+
Fatal error: Type A&B&C is redundant as it is more restrictive than type A&B in %s on line %d

Zend/zend_compile.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6244,7 +6244,7 @@ static void zend_are_intersection_types_redundant(zend_type left_type, zend_type
62446244
larger_type_list = r_type_list;
62456245
}
62466246

6247-
int sum = 0;
6247+
unsigned int sum = 0;
62486248
zend_type *outer_type;
62496249
ZEND_TYPE_LIST_FOREACH(smaller_type_list, outer_type)
62506250
zend_type *inner_type;
@@ -6257,24 +6257,21 @@ static void zend_are_intersection_types_redundant(zend_type left_type, zend_type
62576257
ZEND_TYPE_LIST_FOREACH_END();
62586258

62596259
if (sum == smaller_type_list->num_types) {
6260-
zend_string *l_type_str = zend_type_to_string(left_type);
6261-
zend_string *r_type_str = zend_type_to_string(right_type);
6260+
zend_string *smaller_type_str;
6261+
zend_string *larger_type_str;
6262+
if (flipped) {
6263+
smaller_type_str = zend_type_to_string(right_type);
6264+
larger_type_str = zend_type_to_string(left_type);
6265+
} else {
6266+
smaller_type_str = zend_type_to_string(left_type);
6267+
larger_type_str = zend_type_to_string(right_type);
6268+
}
62626269
if (smaller_type_list->num_types == larger_type_list->num_types) {
6263-
if (flipped) {
6264-
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is redundant with type %s",
6265-
ZSTR_VAL(r_type_str), ZSTR_VAL(l_type_str));
6266-
} else {
6267-
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is redundant with type %s",
6268-
ZSTR_VAL(l_type_str), ZSTR_VAL(r_type_str));
6269-
}
6270+
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is redundant with type %s",
6271+
ZSTR_VAL(smaller_type_str), ZSTR_VAL(larger_type_str));
62706272
} else {
6271-
if (flipped) {
6272-
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is less restrictive than type %s",
6273-
ZSTR_VAL(r_type_str), ZSTR_VAL(l_type_str));
6274-
} else {
6275-
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is less restrictive than type %s",
6276-
ZSTR_VAL(l_type_str), ZSTR_VAL(r_type_str));
6277-
}
6273+
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is redundant as it is more restrictive than type %s",
6274+
ZSTR_VAL(larger_type_str), ZSTR_VAL(smaller_type_str));
62786275
}
62796276
}
62806277
}
@@ -6289,8 +6286,8 @@ static void zend_is_intersection_type_redundant_by_single_type(zend_type interse
62896286
if (zend_string_equals_ci(ZEND_TYPE_NAME(*single_intersection_type), ZEND_TYPE_NAME(single_type))) {
62906287
zend_string *single_type_str = zend_type_to_string(single_type);
62916288
zend_string *complete_type = zend_type_to_string(intersection_type);
6292-
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is less restrictive than type %s",
6293-
ZSTR_VAL(single_type_str), ZSTR_VAL(complete_type));
6289+
zend_error_noreturn(E_COMPILE_ERROR, "Type %s is redundant as it is more restrictive than type %s",
6290+
ZSTR_VAL(complete_type), ZSTR_VAL(single_type_str));
62946291
}
62956292
ZEND_TYPE_FOREACH_END();
62966293
}

0 commit comments

Comments
 (0)