@@ -187,13 +187,15 @@ proc semIf(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil):
187187 it[0 ] = forceBool (c, semExprWithType (c, it[0 ], expectedType = getSysType (c.graph, n.info, tyBool)))
188188 it[1 ] = semExprBranch (c, it[1 ], flags, expectedType)
189189 typ = commonType (c, typ, it[1 ])
190- expectedType = typ
190+ if not endsInNoReturn (it[1 ]):
191+ expectedType = typ
191192 closeScope (c)
192193 elif it.len == 1 :
193194 hasElse = true
194195 it[0 ] = semExprBranchScope (c, it[0 ], expectedType)
195196 typ = commonType (c, typ, it[0 ])
196- expectedType = typ
197+ if not endsInNoReturn (it[0 ]):
198+ expectedType = typ
197199 else : illFormedAst (it, c.config)
198200 if isEmptyType (typ) or typ.kind in {tyNil, tyUntyped} or
199201 (not hasElse and efInTypeof notin flags):
@@ -234,7 +236,8 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil)
234236 var expectedType = expectedType
235237 n[0 ] = semExprBranchScope (c, n[0 ], expectedType)
236238 typ = commonType (c, typ, n[0 ].typ)
237- expectedType = typ
239+ if not endsInNoReturn (n[0 ]):
240+ expectedType = typ
238241
239242 var last = n.len - 1
240243 var catchAllExcepts = 0
@@ -295,7 +298,8 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil)
295298 if a.kind != nkFinally:
296299 a[^ 1 ] = semExprBranchScope (c, a[^ 1 ], expectedType)
297300 typ = commonType (c, typ, a[^ 1 ])
298- expectedType = typ
301+ if not endsInNoReturn (a[^ 1 ]):
302+ expectedType = typ
299303 else :
300304 a[^ 1 ] = semExprBranchScope (c, a[^ 1 ])
301305 dec last
@@ -1145,7 +1149,8 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil
11451149 var last = x.len- 1
11461150 x[last] = semExprBranchScope (c, x[last], expectedType)
11471151 typ = commonType (c, typ, x[last])
1148- expectedType = typ
1152+ if not endsInNoReturn (x[last]):
1153+ expectedType = typ
11491154 of nkElifBranch:
11501155 if hasElse: invalidOrderOfBranches (x)
11511156 chckCovered = false
@@ -1154,13 +1159,15 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil
11541159 x[0 ] = forceBool (c, semExprWithType (c, x[0 ], expectedType = getSysType (c.graph, n.info, tyBool)))
11551160 x[1 ] = semExprBranch (c, x[1 ], expectedType = expectedType)
11561161 typ = commonType (c, typ, x[1 ])
1157- expectedType = typ
1162+ if not endsInNoReturn (x[1 ]):
1163+ expectedType = typ
11581164 closeScope (c)
11591165 of nkElse:
11601166 checkSonsLen (x, 1 , c.config)
11611167 x[0 ] = semExprBranchScope (c, x[0 ], expectedType)
11621168 typ = commonType (c, typ, x[0 ])
1163- expectedType = typ
1169+ if not endsInNoReturn (x[0 ]):
1170+ expectedType = typ
11641171 if (chckCovered and covered == toCover (c, n[0 ].typ)) or hasElse:
11651172 message (c.config, x.info, warnUnreachableElse)
11661173 hasElse = true
0 commit comments