pkl
pkl copied to clipboard
Function type casts/type checks do not handle parameter types and return types
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)
^^^^^^