Allow union types to be used as return values

Blocks #2559