A sum-type defined as type Foo : SomeStructure | nothing
A function with no overloads that takes a SomeStructure ref parameter
A call site to the function which passes a variable of type Foo as the argument
In the current compiler implementation, the type dispatcher will be generated and only one overload is detected (correct) so the parameter is assumed to always be of type SomeStructure (incorrect).
A sledgehammer approach is to have the type checker analyze all call sites to a type dispatcher and note which types are passed in. These type hints would be used for autogeneration of the dispatcher instead of overload analysis. Main risk here is allowing dispatch on types that are illegal and can be statically verified as not possible to work at runtime.
This is fixed, strictly speaking. Type dispatcher codegen is still shaky but this particular problem has been addressed - using the sledgehammer approach described in the bug.
Consider a program with:
type Foo : SomeStructure | nothing
SomeStructure ref
parameterFoo
as the argumentIn the current compiler implementation, the type dispatcher will be generated and only one overload is detected (correct) so the parameter is assumed to always be of type
SomeStructure
(incorrect).A sledgehammer approach is to have the type checker analyze all call sites to a type dispatcher and note which types are passed in. These type hints would be used for autogeneration of the dispatcher instead of overload analysis. Main risk here is allowing dispatch on types that are illegal and can be statically verified as not possible to work at runtime.