Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0ac57d5
Make zend_type a 2-field struct
nikic Sep 20, 2019
8b62d66
Store pass_by_reference+is_variadic in type mask
nikic Sep 24, 2019
4a9735f
WIP Union types
nikic Sep 25, 2019
8f9c57f
Fetch unresolved classes from autoload table
nikic Oct 18, 2019
9c58da4
Fix coercion error
nikic Oct 18, 2019
48e3379
Remove special exceptions when failing to resolve prop type class
nikic Oct 18, 2019
82cfa0c
Fix the typed reference assignment logic
nikic Oct 18, 2019
c786f78
Make loading in type errors robust
nikic Oct 18, 2019
67c0d29
Add tests for redundant types
nikic Oct 18, 2019
af73a41
Tweak error messages
nikic Oct 18, 2019
4a8d0af
Handle iterable + Traversable
nikic Oct 18, 2019
471c27f
Move test files
nikic Oct 18, 2019
f681fb6
More tests
nikic Oct 18, 2019
20495e1
Check for standalone null/false
nikic Oct 18, 2019
291f52c
Use smart_str for type error
nikic Oct 18, 2019
b49438b
Proper type error for union types
nikic Oct 18, 2019
887656d
Fix weak typing logic
nikic Oct 18, 2019
24f863a
Cleanup MAY_BE_BOOL
nikic Oct 18, 2019
37b3997
Add weak typing tests
nikic Oct 18, 2019
ccf57e9
Support union types in AST printer
nikic Oct 18, 2019
c1152c9
Add strict type variant of test
nikic Oct 21, 2019
7fc7982
Implement correct incdec handling
nikic Oct 21, 2019
209f7f1
Test property references
nikic Oct 21, 2019
5213df3
Implement full property invariance check
nikic Oct 21, 2019
9e50dfe
Add ReflectionUnionType
nikic Oct 21, 2019
b0f545c
Add a class loading test
nikic Oct 21, 2019
824ed44
Remove unused variable
nikic Oct 21, 2019
f1d05a4
Try to fix ZTS build (untested)
nikic Oct 21, 2019
fad9419
Allocate property type lists on arena
nikic Oct 22, 2019
686e61f
Remove duplicate test
nikic Oct 23, 2019
e0e204d
Add test for void + class
nikic Oct 23, 2019
476adfa
Run coverage job
nikic Oct 23, 2019
e7aecad
Adjust test after property type loading changes
nikic Oct 23, 2019
716cd38
Add test for generator with multiple class return types
nikic Oct 23, 2019
7e7d240
Add test for iterable+Traversable redundancy with extra class
nikic Oct 23, 2019
6abe540
Add inheritance test and fix some related issues
nikic Oct 23, 2019
59802bb
Fixup reflection after rebase
nikic Nov 7, 2019
f85a717
Revert "Run coverage job"
nikic Nov 8, 2019
c06e6c9
Add json skipifs
nikic Nov 8, 2019
956d3a3
Extra variance test
nikic Nov 8, 2019
8bb01a8
Fix issues related to inheritance of internal union types
nikic Nov 8, 2019
3a9ff5d
Properly destroy internal property types
nikic Nov 8, 2019
edcd6d9
Fix missing cache slot increment
nikic Nov 8, 2019
b036ffa
Use goto for common code-paths
nikic Nov 8, 2019
ccbd868
Add test for iterable variance
nikic Nov 8, 2019
54f9bd4
Fix accidental whitespace change
nikic Nov 8, 2019
c443f3b
Apply cache slot fix to jit as well
nikic Nov 8, 2019
b1615d1
Fix file cache
nikic Nov 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix the typed reference assignment logic
This is tricky...
  • Loading branch information
nikic committed Nov 7, 2019
commit 82cfa0c8a603eb7bccd83f520b4231f3fe84876d
57 changes: 41 additions & 16 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -3057,8 +3057,9 @@ ZEND_API zend_bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference

/* The value must satisfy each property type, and coerce to the same value for each property
* type. Remember the first coerced type and value we've seen for this purpose. */
zend_property_info *seen_prop = NULL;
zval seen_value;
zend_property_info *first_prop = NULL;
zval coerced_value;
ZVAL_UNDEF(&coerced_value);

ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE);
ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
Expand All @@ -3069,28 +3070,52 @@ ZEND_API zend_bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference
}

if (result < 0) {
zval tmp;
ZVAL_COPY(&tmp, zv);
if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) {
zend_throw_ref_type_error_zval(prop, zv);
zval_ptr_dtor(&tmp);
return 0;
}
if (seen_prop) {
if (!zend_is_identical(&tmp, &seen_value)) {
zend_throw_conflicting_coercion_error(seen_prop, prop, zv);
if (!first_prop) {
first_prop = prop;
ZVAL_COPY(&coerced_value, zv);
if (!zend_verify_weak_scalar_type_hint(
ZEND_TYPE_FULL_MASK(prop->type), &coerced_value)) {
zend_throw_ref_type_error_zval(prop, zv);
zval_ptr_dtor(&coerced_value);
return 0;
}
} else if (Z_ISUNDEF(coerced_value)) {
/* A previous property did not require coercion, but this one does,
* so they are incompatible. */
zend_throw_conflicting_coercion_error(first_prop, prop, zv);
return 0;
} else {
seen_prop = prop;
ZVAL_COPY_VALUE(&seen_value, &tmp);
zval tmp;
ZVAL_COPY(&tmp, zv);
if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) {
zend_throw_ref_type_error_zval(prop, zv);
zval_ptr_dtor(&tmp);
zval_ptr_dtor(&coerced_value);
return 0;
}
if (!zend_is_identical(&coerced_value, &tmp)) {
zend_throw_conflicting_coercion_error(first_prop, prop, zv);
zval_ptr_dtor(&tmp);
zval_ptr_dtor(&coerced_value);
return 0;
}
}
} else {
if (!first_prop) {
first_prop = prop;
} else if (!Z_ISUNDEF(coerced_value)) {
/* A previous property required coercion, but this one doesn't,
* so they are incompatible. */
zend_throw_conflicting_coercion_error(first_prop, prop, zv);
zval_ptr_dtor(&coerced_value);
return 0;
}
}
} ZEND_REF_FOREACH_TYPE_SOURCES_END();

if (seen_prop) {
if (!Z_ISUNDEF(coerced_value)) {
zval_ptr_dtor(zv);
ZVAL_COPY_VALUE(zv, &seen_value);
ZVAL_COPY_VALUE(zv, &coerced_value);
}

return 1;
Expand Down