-
Notifications
You must be signed in to change notification settings - Fork 86
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
[Bug] Type conditions should be lazy evaluated #125
Comments
i am confused. why should this code work? you want an |
Yeah in this example |
It should work like so @b1ek: fun foo(val: Text) {
if val is Text: val = "hello"
else: val = 12
}
foo("test") The function should not throw error. Because the value will always be Right now it errors that |
I think this issue should only cover type evaluations that can be known at compile time. We fallback to the regular behavior when some arithmetic comparison is detected. |
Do types even exist at runtime? I mean, this code:
compiles to this: __0_var="hi!"
if [ 1 != 0 ]; then # the "if var is Text" part
echo "${__0_var}"
fi and |
@b1ek Types do not exist at runtime. All |
@Ph0enixKM, that's called dead code, and it should be errored out at compile time. But the originally discussed issue simply asks for union types. |
@mks-h That's something else. It's simply what Typescript is doing with the if's that can narrow down the type of variable when conditioned: const test: string | number
if (typeof test === "number") {
// Here `test` is of type `number` and not `string | number`
} |
Currently type condition's aren't lazy evaluated which causes the following code to fail:
Error:
Cannot assign value of type 'Num' to a variable of type 'Text'
The text was updated successfully, but these errors were encountered: