Skip to content

Commit 28eabbe

Browse files
ondrejmirtesclaude
andcommitted
Declare ExpressionResult's properties by the generated declaration
The native class declared its promoted optional properties with their parameter defaults (null, false, []), while the twin's promoted properties have none — reflection reported default values the twin does not have. construct() writes every slot anyway, so the generated declareProperties() replaces the hand-written list, and the slot writers clear IS_PROP_UNINIT the way the engine's first write of a typed property does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 0b49b0b commit 28eabbe

2 files changed

Lines changed: 14 additions & 35 deletions

File tree

‎turbo-ext/src/ExpressionResult.cpp‎

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ zval *argOf(zval *slot)
8282
return Z_TYPE_P(slot) == IS_NULL ? NULL : slot;
8383
}
8484

85+
/* the constructor's first write of a slot (a typed promoted property is
86+
* uninitialized until then): IS_PROP_UNINIT is cleared as the engine's
87+
* property write clears it */
8588
void writeSlot(zend_object *object, uint32_t slot, zval *value)
8689
{
8790
zval *p = OBJ_PROP_NUM(object, slot);
@@ -90,11 +93,14 @@ void writeSlot(zend_object *object, uint32_t slot, zval *value)
9093
} else {
9194
ZVAL_NULL(p);
9295
}
96+
Z_PROP_FLAG_P(p) = 0;
9397
}
9498

9599
void writeBoolSlot(zend_object *object, uint32_t slot, bool value)
96100
{
97-
ZVAL_BOOL(OBJ_PROP_NUM(object, slot), value);
101+
zval *p = OBJ_PROP_NUM(object, slot);
102+
ZVAL_BOOL(p, value);
103+
Z_PROP_FLAG_P(p) = 0;
98104
}
99105

100106
/* new ShouldNotHappenException($message) */
@@ -217,7 +223,9 @@ class ExpressionResult
217223
if (a.specifiedTypes != NULL) {
218224
writeSlot(object, slots::specifiedTypes, a.specifiedTypes);
219225
} else {
220-
ZVAL_EMPTY_ARRAY(OBJ_PROP_NUM(object, slots::specifiedTypes));
226+
zval *p = OBJ_PROP_NUM(object, slots::specifiedTypes);
227+
ZVAL_EMPTY_ARRAY(p);
228+
Z_PROP_FLAG_P(p) = 0;
221229
}
222230
writeSlot(object, slots::cachedType, a.cachedType);
223231
writeSlot(object, slots::cachedNativeType, a.cachedNativeType);
@@ -1496,38 +1504,10 @@ void pt_register_expression_result()
14961504
reg::Class cls("PHPStan\\Analyser\\ExpressionResult");
14971505
ptdecl::ExpressionResult::declareClass(cls);
14981506
cls.privateClassConstantString("READ_VARIABLE_NAMES_ATTRIBUTE", "readVariableNames");
1499-
/* the twin's properties in declaration order (the OBJ_PROP_NUM slots) */
1500-
cls.privateNullProperty("typeCallback");
1501-
cls.privateNullProperty("specifyTypesCallback");
1502-
cls.privateNullProperty("createTypesCallback");
1503-
cls.privateTypedClassPropertyDefaultNull("truthyScope", pt_er_scope);
1504-
cls.privateTypedClassPropertyDefaultNull("falseyScope", pt_er_scope);
1505-
cls.privateTypedBoolProperty("extensionsDeclined", false);
1506-
cls.privateTypedClassProperty("expressionTypeResolverExtensions", "PHPStan\\DependencyInjection\\ExtensionsCollection", false);
1507-
cls.privateTypedClassProperty("defaultNarrowingHelper", "PHPStan\\Analyser\\ExprHandler\\Helper\\DefaultNarrowingHelper", false);
1508-
cls.privateTypedClassProperty("scope", pt_er_scope, false);
1509-
cls.privateTypedClassProperty("beforeScope", pt_er_scope, false);
1510-
cls.privateTypedClassProperty("expr", "PhpParser\\Node\\Expr", false);
1511-
cls.privateTypedProperty("hasYield", MAY_BE_BOOL);
1512-
cls.privateTypedProperty("isAlwaysTerminating", MAY_BE_BOOL);
1513-
cls.privateTypedProperty("throwPoints", MAY_BE_ARRAY);
1514-
cls.privateTypedProperty("impurePoints", MAY_BE_ARRAY);
1515-
cls.privateTypedBoolProperty("containsNullsafe", false);
1516-
cls.privateTypedClassPropertyDefaultNull("issetabilityDescriptor", "PHPStan\\Analyser\\IssetabilityDescriptor");
1517-
cls.privateTypedClassPropertyDefaultNull("truthyScopeOverrideResult", pt_er_self);
1518-
cls.privateTypedClassPropertyDefaultNull("falseyScopeOverrideResult", pt_er_self);
1519-
cls.privateTypedClassPropertyDefaultNull("type", pt_er_type);
1520-
cls.privateTypedClassPropertyDefaultNull("nativeType", pt_er_type);
1521-
cls.privateTypedClassPropertyDefaultNull("argsResult", "PHPStan\\Analyser\\ArgsResult");
1522-
cls.privateTypedClassPropertyDefaultNull("variableFlow", "PHPStan\\Analyser\\VariableFlow");
1523-
cls.privateTypedArrayPropertyDefaultEmpty("specifiedTypes");
1524-
cls.privateTypedClassPropertyDefaultNull("cachedType", pt_er_type);
1525-
cls.privateTypedClassPropertyDefaultNull("cachedNativeType", pt_er_type);
1526-
cls.privateTypedClassPropertyDefaultNull("resolvedType", pt_er_type);
1527-
cls.privateTypedClassPropertyDefaultNull("resolvedNativeType", pt_er_type);
1528-
cls.privateTypedClassPropertyDefaultNull("projectedType", pt_er_type);
1529-
cls.privateTypedClassPropertyDefaultNull("projectedNativeType", pt_er_type);
1530-
cls.privateTypedPropertyDefaultNull("readVariableNames", MAY_BE_ARRAY);
1507+
/* the twin's properties in declaration order (the OBJ_PROP_NUM slots);
1508+
* the promoted ones have no default value, construct() writes every
1509+
* slot */
1510+
ptdecl::ExpressionResult::declareProperties(cls);
15311511

15321512
cls.method("__construct", reg::Public, 11, {
15331513
reg::obj("expressionTypeResolverExtensions", "PHPStan\\DependencyInjection\\ExtensionsCollection"),

‎turbo-ext/tests/signature-parity.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
*/
3636
$knownDrift = [
3737
'PhpParser\\NodeTraverser' => 'pending',
38-
'PHPStan\\Analyser\\ExpressionResult' => 'pending',
3938
'PHPStan\\Analyser\\ExpressionResultStorage' => 'pending',
4039
'PHPStan\\Analyser\\TypeSpecifierContext' => 'pending',
4140
'PHPStan\\Analyser\\VariableLivenessResolver' => 'pending',

0 commit comments

Comments
 (0)