Fantom Shell v1.0.79
fansh> |->|{}.retype(|->|?#)
sys::ArgErr: Not a Func type: |->sys::Void|?
fan.sys.Func.retype (Func.java:300)
I'm aware a similar nuance has been discussed previously on the forum, and that the underlying cause is that a nullable Type is technically not a pure func type; because nullability is a feature of where the Type is applied and not of the Type itself.
Hence the following works okay:
fansh> |->|{}.retype(|->|#)
|->sys::Void|
These runtime mistakes are easy to overlook and difficult to guard against; could Func.retype() be updated to cater for nullable Types?
brianThu 7 Dec 2023
What do you mean by cater for nullable types? It seems like the current behavior is correct that you must pass in a function type (which is for reflection)
SlimerDudeFri 8 Dec 2023
Hi, I would ask for retype() to be lenient and automatically call .toNonNullable() on the given Type.
For instance, This code looks perfectly fine as it retypes a func to the Field type, but it actually throws "Not a func type".
SlimerDude Thu 7 Dec 2023
Hi, I was expecting the following to work:
I'm aware a similar nuance has been discussed previously on the forum, and that the underlying cause is that a nullable Type is technically not a pure func type; because nullability is a feature of where the Type is applied and not of the Type itself.
Hence the following works okay:
These runtime mistakes are easy to overlook and difficult to guard against; could
Func.retype()
be updated to cater for nullable Types?brian Thu 7 Dec 2023
What do you mean by cater for nullable types? It seems like the current behavior is correct that you must pass in a function type (which is for reflection)
SlimerDude Fri 8 Dec 2023
Hi, I would ask for
retype()
to be lenient and automatically call.toNonNullable()
on the given Type.For instance, This code looks perfectly fine as it retypes a func to the Field type, but it actually throws
"Not a func type"
.It would take a very special kind of Fantom developer to understand they just need to write
newFn.retype(#fooFn.type.toNonNullable)
.If not, then I would ask for clearer documentation and a different err msg for this specific nullable case (which arguably, is more work!).
brian Sat 9 Dec 2023
Understand. I pushed a fix