Fix type substitution into variants and records
Variants were working by accident, since {variant, [{"VariantName", [Element]}]} had a similar enough form to the opaque types that would come from something like `type1(type2(int))`, but records were not working, since they have a different form. Now both are handled explicitly so that only the intended forms of each are handled.
This commit is contained in:
parent
4441f6ff37
commit
7eb29827a6
29
src/hz.erl
29
src/hz.erl
@ -1662,12 +1662,39 @@ substitute_opaque_type(Bindings, {var, VarName}) ->
|
||||
false -> {error, invalid_aci};
|
||||
{_, TypeArg} -> {ok, TypeArg}
|
||||
end;
|
||||
substitute_opaque_type(Bindings, {variant, Args}) ->
|
||||
case substitute_variant_types(Bindings, Args, []) of
|
||||
{ok, Result} -> {ok, {variant, Result}};
|
||||
Error -> Error
|
||||
end;
|
||||
substitute_opaque_type(Bindings, {record, Args}) ->
|
||||
case substitute_record_types(Bindings, Args, []) of
|
||||
{ok, Result} -> {ok, {record, Result}};
|
||||
Error -> Error
|
||||
end;
|
||||
substitute_opaque_type(Bindings, {Connective, Args}) ->
|
||||
case substitute_opaque_types(Bindings, Args, []) of
|
||||
{ok, Result} -> {ok, {Connective, Result}};
|
||||
Error -> Error
|
||||
end;
|
||||
substitute_opaque_type(_Bindings, Type) -> {ok, Type}.
|
||||
substitute_opaque_type(_Bindings, Type) ->
|
||||
{ok, Type}.
|
||||
|
||||
substitute_variant_types(Bindings, [{VariantName, Elements} | Rest], Acc) ->
|
||||
case substitute_opaque_types(Bindings, Elements, []) of
|
||||
{ok, Result} -> substitute_variant_types(Bindings, Rest, [{VariantName, Result} | Acc]);
|
||||
Error -> Error
|
||||
end;
|
||||
substitute_variant_types(_Bindings, [], Acc) ->
|
||||
{ok, lists:reverse(Acc)}.
|
||||
|
||||
substitute_record_types(Bindings, [{ElementName, Type} | Rest], Acc) ->
|
||||
case substitute_opaque_type(Bindings, Type) of
|
||||
{ok, Result} -> substitute_record_types(Bindings, Rest, [{ElementName, Result} | Acc]);
|
||||
Error -> Error
|
||||
end;
|
||||
substitute_record_types(_Bindings, [], Acc) ->
|
||||
{ok, lists:reverse(Acc)}.
|
||||
|
||||
substitute_opaque_types(Bindings, [Next | Rest], Acc) ->
|
||||
case substitute_opaque_type(Bindings, Next) of
|
||||
|
Loading…
x
Reference in New Issue
Block a user