Skip to content

Commit

Permalink
Add inheritance test and fix some related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 25, 2019
1 parent f80b215 commit 471931e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
46 changes: 46 additions & 0 deletions Zend/tests/type_declarations/union_types/inheritance.phpt
@@ -0,0 +1,46 @@
--TEST--
Various inheritance scenarios for properties/methods with union types
--FILE--
<?php

class X {
public A|B|int $prop;
public function method(A|B|int $arg): A|B|int { }

private A|B|int $prop2;
private function method2(A|B|int $arg): A|B|int { }
}

class Y extends X {
}

trait T {
public A|B|int $prop;
public function method(A|B|int $arg): A|B|int { }

private A|B|int $prop2;
private function method2(A|B|int $arg): A|B|int { }
}

class Z {
use T;
}

class U extends X {
use T;
}

class V extends X {
use T;

public A|B|int $prop;
public function method(A|B|int $arg): A|B|int { }

private A|B|int $prop2;
private function method2(A|B|int $arg): A|B|int { }
}

?>
===DONE===
--EXPECT--
===DONE===
4 changes: 3 additions & 1 deletion Zend/zend_inheritance.c
Expand Up @@ -43,7 +43,9 @@ static void overridden_ptr_dtor(zval *zv) /* {{{ */
static void zend_type_copy_ctor(zend_type *type) {
if (ZEND_TYPE_HAS_LIST(*type)) {
zend_type_list *old_list = ZEND_TYPE_LIST(*type);
zend_type_list *new_list = emalloc(ZEND_TYPE_LIST_SIZE(old_list->num_types));
size_t size = ZEND_TYPE_LIST_SIZE(old_list->num_types);
zend_type_list *new_list = ZEND_TYPE_USES_ARENA(*type)
? zend_arena_alloc(&CG(arena), size) : emalloc(size);
memcpy(new_list, old_list, ZEND_TYPE_LIST_SIZE(old_list->num_types));
ZEND_TYPE_SET_PTR(*type, new_list);

Expand Down
27 changes: 14 additions & 13 deletions ext/opcache/zend_accelerator_util_funcs.c
Expand Up @@ -235,20 +235,21 @@ static void zend_hash_clone_prop_info(HashTable *ht)

if (ZEND_TYPE_HAS_LIST(prop_info->type)) {
zend_type_list *list = ZEND_TYPE_LIST(prop_info->type);
ZEND_ASSERT(IN_ARENA(list));
list = ARENA_REALLOC(list);
ZEND_TYPE_SET_PTR(prop_info->type, list);

void **entry;
ZEND_TYPE_LIST_FOREACH_PTR(ZEND_TYPE_LIST(prop_info->type), entry) {
if (ZEND_TYPE_LIST_IS_CE(*entry)) {
zend_class_entry *ce = ZEND_TYPE_LIST_GET_CE(*entry);
if (IN_ARENA(ce)) {
ce = ARENA_REALLOC(ce);
*entry = ZEND_TYPE_LIST_ENCODE_CE(ce);
if (IN_ARENA(list)) {
list = ARENA_REALLOC(list);
ZEND_TYPE_SET_PTR(prop_info->type, list);

void **entry;
ZEND_TYPE_LIST_FOREACH_PTR(ZEND_TYPE_LIST(prop_info->type), entry) {
if (ZEND_TYPE_LIST_IS_CE(*entry)) {
zend_class_entry *ce = ZEND_TYPE_LIST_GET_CE(*entry);
if (IN_ARENA(ce)) {
ce = ARENA_REALLOC(ce);
*entry = ZEND_TYPE_LIST_ENCODE_CE(ce);
}
}
}
} ZEND_TYPE_LIST_FOREACH_END();
} ZEND_TYPE_LIST_FOREACH_END();
}
} else if (ZEND_TYPE_HAS_CE(prop_info->type)) {
zend_class_entry *ce = ZEND_TYPE_CE(prop_info->type);
if (IN_ARENA(ce)) {
Expand Down

0 comments on commit 471931e

Please sign in to comment.