Improved type inference (fixes #1011)

This PR changes type inference to consider inferences made *to* a type parameter in a union type secondary to inferences made directly *to* that same type parameter. See the discussion on #1011 for further details.