pkl icon indicating copy to clipboard operation
pkl copied to clipboard

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

Open bioball opened this issue 5 months ago • 0 comments

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)
                          ^^^^^^

bioball avatar Sep 06 '24 04:09 bioball