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

Open
opened 2025-12-30 01:22:05 +01:00 by adam · 0 comments
Owner

Originally created by @bioball on GitHub (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)
                          ^^^^^^
Originally created by @bioball on GitHub (Sep 6, 2024). This snippet this evaluates to `result = true`: ```pkl 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: ```pkl 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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#204