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
pull/20/head
韩天峰 1 month ago
parent bd802ba9c4
commit 37eb77a0b8
  1. 2
      src/Parser/PropertyAccessTrait.php
  2. 43
      tests/compiler/object_property/native-scalar-property-namespaced-diagnostic.phpt

@ -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);

@ -0,0 +1,43 @@
--TEST--
Native scalar property diagnostics escape namespaced class names in generated C++ strings
--FILE--
<?php
namespace Px\C4129Repro {
use native_types;
class NamespacedScalarProperty
{
public int $intValue = 0;
public float $floatValue = 0.0;
public bool $boolValue = false;
public function assign(array $config): void
{
$this->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"
Loading…
Cancel
Save