#Checking whether types can coerce to each other
1 messages · Page 1 of 1 (latest)
There are many ways to coerce types, which can have many properties. Can you be more specific?
I want to check whether @as(TA, @as(TB, some_value)) works.
the simple answer is to just do it
That would give a compile error tho
exactly
then you'll need to use @typeInfo and compare all of the possible incompatibilities; there isn't anything for this in the stdlib
@TypeOf(a, b) returns the peer-resolved type of a and b. It would be nice if it returned an optional when given more than one argument
I think that'd be best as a separate built-in which takes the actual types, e.g. @TypeResolve(T1, T2).?
It would, yeah
I second this, @TypeOf needs a value, a @TypeResolve would be more applicable to more situations
FWIW, just wanted to do exactly the same. A pity it's not possible (without manually parsing the std.builtin.Type structure and hopefully reimplementing the coercion rules correctly).
This looks to me different than the original problem. Peer-resolution IIUC finds a common type that all arguments coerce to? In that case I'm not sure how it can be used to see if TA coerces to TB.