From 37eb77a0b884013b0fdfb68db745f3f05165814c Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 14 Jul 2026 11:59:28 +0800 Subject: [PATCH] test(compiler): add native scalar property diagnostic test for namespaced class names - Add test case for namespaced class name escaping in C++ string generation - Verify proper error message display for type mismatch in namespaced properties - Test native scalar property assignments with configuration arrays - Validate TypeError handling for invalid type assignments in namespaced context fix(compiler): ensure namespaced class names are properly escaped in property type checks - Update genCharPtr call with escape parameter set to true - Fix object property type check display name generation for namespaced classes - Maintain backward compatibility with existing property access patterns --- src/Parser/PropertyAccessTrait.php | 2 +- ...scalar-property-namespaced-diagnostic.phpt | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/compiler/object_property/native-scalar-property-namespaced-diagnostic.phpt diff --git a/src/Parser/PropertyAccessTrait.php b/src/Parser/PropertyAccessTrait.php index 4eea0b92..39f91829 100644 --- a/src/Parser/PropertyAccessTrait.php +++ b/src/Parser/PropertyAccessTrait.php @@ -544,7 +544,7 @@ trait PropertyAccessTrait return $rightExpr; } if ($rightType === Type::VAR && ($helper = $this->getNativeScalarPropertyTypeCheckHelper($def)) !== null) { - return $helper . '(' . $rightExpr . ', ' . $this->genCharPtr($this->getObjectPropertyTypeCheckDisplayName($left)) . ')'; + return $helper . '(' . $rightExpr . ', ' . $this->genCharPtr($this->getObjectPropertyTypeCheckDisplayName($left), true) . ')'; } $rightClass = $this->detectClassOfExpr($right); diff --git a/tests/compiler/object_property/native-scalar-property-namespaced-diagnostic.phpt b/tests/compiler/object_property/native-scalar-property-namespaced-diagnostic.phpt new file mode 100644 index 00000000..4a45a8de --- /dev/null +++ b/tests/compiler/object_property/native-scalar-property-namespaced-diagnostic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Native scalar property diagnostics escape namespaced class names in generated C++ strings +--FILE-- +intValue = $config['int'] ?? 1; + $this->floatValue = $config['float'] ?? 2.5; + $this->boolValue = $config['bool'] ?? false; + } + } +} + +namespace { + function main(): void + { + $box = new \Px\C4129Repro\NamespacedScalarProperty(); + $box->assign(['int' => 12, 'float' => 3.5, 'bool' => true]); + + var_dump($box->intValue, $box->floatValue, $box->boolValue); + + try { + $box->assign(['int' => 1, 'float' => 2.5, 'bool' => 'invalid']); + } catch (\TypeError $e) { + var_dump($e->getMessage()); + } + } +} +?> +--EXPECT-- +int(12) +float(3.5) +bool(true) +string(96) "Cannot assign string to property Px\C4129Repro\NamespacedScalarProperty::$boolValue of type bool"