@@ -1308,27 +1308,50 @@ static inheritance_status full_property_types_compatible(
13081308static ZEND_COLD void emit_incompatible_property_error (
13091309 const zend_property_info * child , const zend_property_info * parent , prop_variance variance ) {
13101310 zend_string * type_str = zend_type_to_string_resolved (parent -> type , parent -> ce );
1311- zend_error_noreturn (E_COMPILE_ERROR ,
1312- "Type of %s::$%s must be %s%s (as in class %s)" ,
1313- ZSTR_VAL (child -> ce -> name ),
1314- zend_get_unmangled_property_name (child -> name ),
1315- variance == PROP_INVARIANT ? "" :
1316- variance == PROP_COVARIANT ? "subtype of " : "supertype of " ,
1317- ZSTR_VAL (type_str ),
1318- ZSTR_VAL (parent -> ce -> name ));
1311+ uint32_t line = zend_get_typed_member_line (child );
1312+ if (line && child -> ce -> type == ZEND_USER_CLASS ) {
1313+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , line ,
1314+ "Type of %s::$%s must be %s%s (as in class %s)" ,
1315+ ZSTR_VAL (child -> ce -> name ),
1316+ zend_get_unmangled_property_name (child -> name ),
1317+ variance == PROP_INVARIANT ? "" :
1318+ variance == PROP_COVARIANT ? "subtype of " : "supertype of " ,
1319+ ZSTR_VAL (type_str ),
1320+ ZSTR_VAL (parent -> ce -> name ));
1321+ } else {
1322+ zend_error_noreturn (E_COMPILE_ERROR ,
1323+ "Type of %s::$%s must be %s%s (as in class %s)" ,
1324+ ZSTR_VAL (child -> ce -> name ),
1325+ zend_get_unmangled_property_name (child -> name ),
1326+ variance == PROP_INVARIANT ? "" :
1327+ variance == PROP_COVARIANT ? "subtype of " : "supertype of " ,
1328+ ZSTR_VAL (type_str ),
1329+ ZSTR_VAL (parent -> ce -> name ));
1330+ }
13191331}
13201332
13211333static ZEND_COLD void emit_set_hook_type_error (const zend_property_info * child , const zend_property_info * parent )
13221334{
13231335 zend_type set_type = parent -> hooks [ZEND_PROPERTY_HOOK_SET ]-> common .arg_info [0 ].type ;
13241336 zend_string * type_str = zend_type_to_string_resolved (set_type , parent -> ce );
1325- zend_error_noreturn (E_COMPILE_ERROR ,
1326- "Set type of %s::$%s must be supertype of %s (as in %s %s)" ,
1327- ZSTR_VAL (child -> ce -> name ),
1328- zend_get_unmangled_property_name (child -> name ),
1329- ZSTR_VAL (type_str ),
1330- zend_get_object_type_case (parent -> ce , false),
1331- ZSTR_VAL (parent -> ce -> name ));
1337+ uint32_t line = zend_get_typed_member_line (child );
1338+ if (line && child -> ce -> type == ZEND_USER_CLASS ) {
1339+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , line ,
1340+ "Set type of %s::$%s must be supertype of %s (as in %s %s)" ,
1341+ ZSTR_VAL (child -> ce -> name ),
1342+ zend_get_unmangled_property_name (child -> name ),
1343+ ZSTR_VAL (type_str ),
1344+ zend_get_object_type_case (parent -> ce , false),
1345+ ZSTR_VAL (parent -> ce -> name ));
1346+ } else {
1347+ zend_error_noreturn (E_COMPILE_ERROR ,
1348+ "Set type of %s::$%s must be supertype of %s (as in %s %s)" ,
1349+ ZSTR_VAL (child -> ce -> name ),
1350+ zend_get_unmangled_property_name (child -> name ),
1351+ ZSTR_VAL (type_str ),
1352+ zend_get_object_type_case (parent -> ce , false),
1353+ ZSTR_VAL (parent -> ce -> name ));
1354+ }
13321355}
13331356
13341357static inheritance_status verify_property_type_compatibility (
@@ -1621,13 +1644,24 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
16211644static void emit_incompatible_class_constant_error (
16221645 const zend_class_constant * child , const zend_class_constant * parent , const zend_string * const_name ) {
16231646 zend_string * type_str = zend_type_to_string_resolved (parent -> type , parent -> ce );
1624- zend_error_noreturn (E_COMPILE_ERROR ,
1625- "Type of %s::%s must be compatible with %s::%s of type %s" ,
1626- ZSTR_VAL (child -> ce -> name ),
1627- ZSTR_VAL (const_name ),
1628- ZSTR_VAL (parent -> ce -> name ),
1629- ZSTR_VAL (const_name ),
1630- ZSTR_VAL (type_str ));
1647+ uint32_t line = zend_get_typed_member_line (child );
1648+ if (line && child -> ce -> type == ZEND_USER_CLASS ) {
1649+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , line ,
1650+ "Type of %s::%s must be compatible with %s::%s of type %s" ,
1651+ ZSTR_VAL (child -> ce -> name ),
1652+ ZSTR_VAL (const_name ),
1653+ ZSTR_VAL (parent -> ce -> name ),
1654+ ZSTR_VAL (const_name ),
1655+ ZSTR_VAL (type_str ));
1656+ } else {
1657+ zend_error_noreturn (E_COMPILE_ERROR ,
1658+ "Type of %s::%s must be compatible with %s::%s of type %s" ,
1659+ ZSTR_VAL (child -> ce -> name ),
1660+ ZSTR_VAL (const_name ),
1661+ ZSTR_VAL (parent -> ce -> name ),
1662+ ZSTR_VAL (const_name ),
1663+ ZSTR_VAL (type_str ));
1664+ }
16311665}
16321666
16331667static inheritance_status class_constant_types_compatible (const zend_class_constant * parent , const zend_class_constant * child )
0 commit comments