Deriving session and union types for objects