-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Interesting quirk, should be aware of #27
Comments
Definitely yes, should throw an error for first I actually think this is a very good example in how typl differs from other static type checkers and is suited to JS style. |
:) |
BTW, the reason why the second pass matters here is, if I wasn't careful to preserve this behavior, on the second pass The way this works is, if an identifier is determined to be So, in the first pass, the On the second pass, even though the scope binding for That's basically how Typl uses the lexical ordering to infer different types (specifically |
There's nothing to do for this issue... I just want to document this quirk somewhere.
Think carefully about this code. What do you expect to happen? Any errors?
This code requires a second pass, because of the
foo(..)
hoisting. On the first pass,x
is initially implied asundef
, then it's re-implied asnumber
. So... on the second pass, would we expect the firstfoo(x)
to throw an error or not?I claim: yes it should throw an error. Even though
x
becomesnumber
later in the code, at the moment we first seefoo(x)
, it's stillundef
. On that second pass, we knowfoo(..)
expects anumber
, so we should get an error about argument type mismatch.Likewise, for the second
foo(x)
... since that one comes aftera = 3
, by that moment (even on the first pass), we know thatfoo(x)
is trying to pass a number. So... since that's valid, no error should be thrown for that line.The output (currently) is:
The text was updated successfully, but these errors were encountered: