Skip to content

Commit

Permalink
Fix AttrSystemInitialValue on overridden properties
Browse files Browse the repository at this point in the history
Summary:
If its set on the parent prop, but not on the child, we need to
explicitly clear it on the child's property.

Reviewed By: ricklavoie

Differential Revision: D13084126

fbshipit-source-id: 3de06f6239f770efe60a3da582060c5fbab6d4dc
  • Loading branch information
Mark Williams authored and hhvm-bot committed Nov 16, 2018
1 parent 4d57c97 commit c891e64
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hphp/runtime/vm/class.cpp
Expand Up @@ -2594,9 +2594,9 @@ void Class::setProperties() {
if (preProp->attrs() & AttrNoImplicitNullable) {
prop.attrs |= AttrNoImplicitNullable;
}
if (preProp->attrs() & AttrSystemInitialValue) {
prop.attrs |= AttrSystemInitialValue;
}
attrSetter(prop.attrs,
preProp->attrs() & AttrSystemInitialValue,
AttrSystemInitialValue);
if (preProp->attrs() & AttrInitialSatisfiesTC) {
prop.attrs |= AttrInitialSatisfiesTC;
}
Expand Down Expand Up @@ -2651,9 +2651,9 @@ void Class::setProperties() {
if (preProp->attrs() & AttrNoImplicitNullable) {
prop.attrs |= AttrNoImplicitNullable;
}
if (preProp->attrs() & AttrSystemInitialValue) {
prop.attrs |= AttrSystemInitialValue;
}
attrSetter(prop.attrs,
preProp->attrs() & AttrSystemInitialValue,
AttrSystemInitialValue);
if (preProp->attrs() & AttrInitialSatisfiesTC) {
prop.attrs |= AttrInitialSatisfiesTC;
}
Expand Down
36 changes: 36 additions & 0 deletions hphp/test/slow/object_property/system_initial_value.php
@@ -0,0 +1,36 @@
<?hh

class Y {
const A = 'a';
}

class A {
public ImmMap $pub;
protected ImmMap $prot;
}

class X extends A {
public ImmMap $pub = ImmMap {
Y::A => 42,
};
protected ImmMap $prot = ImmMap {
Y::A => 24,
};

function getPub() { return $this->pub; }
function getProt() { return $this->prot; }
}

function test() {
return new X;
}

function main() {
for ($i = 1; $i < 100; $i++) {
test();
}
$x = test();
var_dump($x->getPub(), $x->getProt());
}

main();
@@ -0,0 +1,8 @@
object(HH\ImmMap)#202 (1) {
["a"]=>
int(42)
}
object(HH\ImmMap)#203 (1) {
["a"]=>
int(24)
}

0 comments on commit c891e64

Please sign in to comment.