You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classMyClass {
constintFOO=123;
}
typeMyShape=shape(MyClass::FOO => string, // this is fine 123 => string, // expected string literal or class constant}
Discovered while looking into why Shapes::toArray() returns array<arraykey, mixed> instead of array<string,mixed>
The text was updated successfully, but these errors were encountered:
It's there, but apparently is detected as part of the markup. What he actually said is array<string,mixed> not array<arraykey,mixed>, the markup is just hiding some of it.
The reason why this rule exists (I believe) is because shape()s were backed by PHP arrays in 2015.
PHP arrays performed integral type coercion on keys. ['0' => 'zero'] would become [0 => 'zero'].
The typesystem could not model shapes like this, because it wouldn't know about this runtime "helpful" behavior.
type MyShape = shape(
'0' => string,
0 => int
);
This shape is impossible to create in hhvm versions back shapes with PHP arrays.
Since hhvm 4.2.0 PHP arrays (and darrays, the backing type behind shapes), nolonger perform integral key coercion.
However the typechecker still shields you from this dead runtime behavior.
typeMyShape=shape('1' => string,);
Parsing[1002] Shape field name must not be an int-like string (i.e. "123")
--> file.hack
11 | '1' => string,
| ^^^
1 error found.
The blogpost for hhvm 3.28.3 states this directly. Because shapes are darrays under the hood, we are still disallowing user-defined shapes to define integer keys due to intish string array key coercion.
I think we can safely allow int keys in shapes now.
Discovered while looking into why Shapes::toArray() returns
array<arraykey, mixed>
instead ofarray<string,mixed>
The text was updated successfully, but these errors were encountered: