Meta types and dynamic typing

That should be fine - though the generic type is erased at runtime, that just means that a use of payloadbase(int)'s Get and Set will box and unbox the value (effectively coerce between int and any) - but you shouldn’t be able to do anything bad as far as types go. If you were to use payloadbase(payload_class_data)'s Get, it would return a valid playload_class_data, which if the value in question happens to be a payload_struct, that may be a payload_class_data if there was otherwise no call to Set. In the int case, if the payloadbase(int) in question is a payload_int and there had been no call Set previously, Get should produce -1. Invoking either Get or Set on a value with declared type payloadbase(int) vs. payload_int does not matter - the dispatch will use the type of the underlying value (dynamically dispatch). In other words, X:payload_int = payload_int{}; X.Set(1); X.Get() and X:payloadbase(int) = payload_int{}; X.Set(1); X.Get() should produce the same result.

1 Like