Fix issue #6209

Fix issue #6209, and some related issues about constant expression
 - unmatched type between arms
 - unmatched type in range