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
Summary:
Recursion checks are broken on newtypes because we don't model how the runtime resolves alias definitions, and in localization we conflate interpretation of values typed as aliases with alias resolution for well-formedness checks.
As a result, it is trivial to write definitions that pass `hh` but fatal the runtime, and we fail to properly distinguish recursive and non-recursive case types for gating.
This change attempts to bring us closer to what happens at runtime when the backing type structure for a typedef is resolved. When checking a typedef value, we fully expand all aliases. If a case type is reached and we started from an alias, we stop and treat it as opaque. If we started from a case type, we expand case types until we reach the root type. For some intuition, consider the type_structure models of the following two types
```
hphpd> case type A = shape('a' => ?B);
hphpd> case type B = shape('b' => ?A);
hphpd> =type_structure('A')
Dict
(
[kind] => 31
[union_types] => Vec
(
[0] => Dict
(
[kind] => 14
[fields] => Dict
(
[a] => Dict
(
[kind] => 31
[union_types] => Vec
(
[0] => Dict
(
[kind] => 14
[fields] => Dict
(
[b] => Dict
(
[kind] => 32
[case_type] => "A"
)
)
)
)
[case_type] => "B"
[nullable] => true
)
)
)
)
[case_type] => "A"
)
hphpd> =type_structure('B')
Dict
(
[kind] => 31
[union_types] => Vec
(
[0] => Dict
(
[kind] => 14
[fields] => Dict
(
[b] => Dict
(
[kind] => 31
[union_types] => Vec
(
[0] => Dict
(
[kind] => 14
[fields] => Dict
(
[a] => Dict
(
[kind] => 32
[case_type] => "B"
)
)
)
)
[case_type] => "A"
[nullable] => true
)
)
)
)
[case_type] => "B"
)
hphpd>
```
Lift out the alias constraint checking so that cycle detection occurs regardless of whether we have resolved to a `Rhs` value. This fixes a case where you can launder well-formedness errors through newtype.
Reviewed By: viratyosin
Differential Revision: D91863233
fbshipit-source-id: 00ab9e78bc8f80d7a454dc558a421fa349b4aa55
0 commit comments