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

Function type casts/type checks do not handle parameter types and return types #639

Open
bioball opened this issue Sep 6, 2024 · 0 comments

Comments

@bioball
Copy link
Contributor

bioball commented Sep 6, 2024

This snippet this evaluates to result = true:

hidden myFunc = (it: String) -> it

result = myFunc is (Int) -> String

It's not possible to typecheck a function type (beyond simply Function). A better behavior here is probably to just throw an error, because it's impossible to know if above expression should be true or false.

However, we should be able to type cast functions. This snippet does not throw, but should:

hidden myFunc = (it) -> it

hidden fooFunc: (String) -> String = myFunc

result = (fooFunc as (String) -> String).apply(1)

I'd expect an error like:

–– Pkl Error ––
Expected value of type String, but got type Int.
Value: 1

1 | result = (fooFunc as (String) -> String).apply(1)
                          ^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant