Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining a cast function from and to arbitrary types is possible #578

Open
fgaz opened this issue Nov 3, 2022 · 1 comment
Open

Defining a cast function from and to arbitrary types is possible #578

fgaz opened this issue Nov 3, 2022 · 1 comment
Labels
semantics Unexpected or unsound behaviors

Comments

@fgaz
Copy link

fgaz commented Nov 3, 2022

This code typechecks but is unsound:

local function cast<A, B>(a: A) : B
   return a
end

local n : number = cast("not a number")

https://teal-playground.netlify.app/?c=bG9jYWwgZnVuY3Rpb24gY2FzdDxBLCBCPihhOiBBKSA6IEIKICAgcmV0dXJuIGEKZW5kCgpsb2NhbCBzIDogc3RyaW5nID0gY2FzdCgxKQ%3D%3D

Found in #577

@hishamhm hishamhm added the semantics Unexpected or unsound behaviors label Nov 9, 2022
@hishamhm
Copy link
Member

I suspect this is not a coding bug, but a side-effect of the combination of unbound type variables and bivariant types. This may be actually tricky to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semantics Unexpected or unsound behaviors
Projects
None yet
Development

No branches or pull requests

2 participants