pyret-lang
pyret-lang copied to clipboard
Cases `ref` bindings incorrectly type the variable as `ref T` instead of `T`
A simple example:
data Foo:
| c(ref a :: String)
end
print(cases(Foo) c("a"):
| c(ref x) => x + x
end)
This prints "aa" at runtime, since the ref x pattern unpacks the reference, which results in a simple string addition. However, the type checker will incorrectly type x to be ref String and reject the addition.
Additionally, the type checker allows ref variables to be mentioned in the cases pattern without the ref keyword, even though this behavior is not allowed at runtime ("Cases on ref field needs to use ref"). It should probably be rejected during type checking.