[Refactoring] common type calculation

Separate the conditional expression logic into free function `toCommonType`.