@@ -1308,27 +1308,48 @@ 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+ if (child -> line && child -> ce -> type == ZEND_USER_CLASS ) {
1312+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , child -> line ,
1313+ "Type of %s::$%s must be %s%s (as in class %s)" ,
1314+ ZSTR_VAL (child -> ce -> name ),
1315+ zend_get_unmangled_property_name (child -> name ),
1316+ variance == PROP_INVARIANT ? "" :
1317+ variance == PROP_COVARIANT ? "subtype of " : "supertype of " ,
1318+ ZSTR_VAL (type_str ),
1319+ ZSTR_VAL (parent -> ce -> name ));
1320+ } else {
1321+ zend_error_noreturn (E_COMPILE_ERROR ,
1322+ "Type of %s::$%s must be %s%s (as in class %s)" ,
1323+ ZSTR_VAL (child -> ce -> name ),
1324+ zend_get_unmangled_property_name (child -> name ),
1325+ variance == PROP_INVARIANT ? "" :
1326+ variance == PROP_COVARIANT ? "subtype of " : "supertype of " ,
1327+ ZSTR_VAL (type_str ),
1328+ ZSTR_VAL (parent -> ce -> name ));
1329+ }
13191330}
13201331
13211332static ZEND_COLD void emit_set_hook_type_error (const zend_property_info * child , const zend_property_info * parent )
13221333{
13231334 zend_type set_type = parent -> hooks [ZEND_PROPERTY_HOOK_SET ]-> common .arg_info [0 ].type ;
13241335 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 ));
1336+ if (child -> line && child -> ce -> type == ZEND_USER_CLASS ) {
1337+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , child -> line ,
1338+ "Set type of %s::$%s must be supertype of %s (as in %s %s)" ,
1339+ ZSTR_VAL (child -> ce -> name ),
1340+ zend_get_unmangled_property_name (child -> name ),
1341+ ZSTR_VAL (type_str ),
1342+ zend_get_object_type_case (parent -> ce , false),
1343+ ZSTR_VAL (parent -> ce -> name ));
1344+ } else {
1345+ zend_error_noreturn (E_COMPILE_ERROR ,
1346+ "Set type of %s::$%s must be supertype of %s (as in %s %s)" ,
1347+ ZSTR_VAL (child -> ce -> name ),
1348+ zend_get_unmangled_property_name (child -> name ),
1349+ ZSTR_VAL (type_str ),
1350+ zend_get_object_type_case (parent -> ce , false),
1351+ ZSTR_VAL (parent -> ce -> name ));
1352+ }
13321353}
13331354
13341355static inheritance_status verify_property_type_compatibility (
@@ -1621,13 +1642,23 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
16211642static void emit_incompatible_class_constant_error (
16221643 const zend_class_constant * child , const zend_class_constant * parent , const zend_string * const_name ) {
16231644 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 ));
1645+ if (child -> line && child -> ce -> type == ZEND_USER_CLASS ) {
1646+ zend_error_at_noreturn (E_COMPILE_ERROR , child -> ce -> info .user .filename , child -> line ,
1647+ "Type of %s::%s must be compatible with %s::%s of type %s" ,
1648+ ZSTR_VAL (child -> ce -> name ),
1649+ ZSTR_VAL (const_name ),
1650+ ZSTR_VAL (parent -> ce -> name ),
1651+ ZSTR_VAL (const_name ),
1652+ ZSTR_VAL (type_str ));
1653+ } else {
1654+ zend_error_noreturn (E_COMPILE_ERROR ,
1655+ "Type of %s::%s must be compatible with %s::%s of type %s" ,
1656+ ZSTR_VAL (child -> ce -> name ),
1657+ ZSTR_VAL (const_name ),
1658+ ZSTR_VAL (parent -> ce -> name ),
1659+ ZSTR_VAL (const_name ),
1660+ ZSTR_VAL (type_str ));
1661+ }
16311662}
16321663
16331664static inheritance_status class_constant_types_compatible (const zend_class_constant * parent , const zend_class_constant * child )
0 commit comments