@@ -187,13 +187,15 @@ proc semIf(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil):
187
187
it[0] = forceBool(c, semExprWithType(c, it[0], expectedType = getSysType(c.graph, n.info, tyBool)))
188
188
it[1] = semExprBranch(c, it[1], flags, expectedType)
189
189
typ = commonType(c, typ, it[1])
190
- expectedType = typ
190
+ if not endsInNoReturn(it[1]):
191
+ expectedType = typ
191
192
closeScope(c)
192
193
elif it.len == 1:
193
194
hasElse = true
194
195
it[0] = semExprBranchScope(c, it[0], expectedType)
195
196
typ = commonType(c, typ, it[0])
196
- expectedType = typ
197
+ if not endsInNoReturn(it[0]):
198
+ expectedType = typ
197
199
else: illFormedAst(it, c.config)
198
200
if isEmptyType(typ) or typ.kind in {tyNil, tyUntyped} or
199
201
(not hasElse and efInTypeof notin flags):
@@ -234,7 +236,8 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil)
234
236
var expectedType = expectedType
235
237
n[0] = semExprBranchScope(c, n[0], expectedType)
236
238
typ = commonType(c, typ, n[0].typ)
237
- expectedType = typ
239
+ if not endsInNoReturn(n[0]):
240
+ expectedType = typ
238
241
239
242
var last = n.len - 1
240
243
var catchAllExcepts = 0
@@ -295,7 +298,8 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil)
295
298
if a.kind != nkFinally:
296
299
a[^1] = semExprBranchScope(c, a[^1], expectedType)
297
300
typ = commonType(c, typ, a[^1])
298
- expectedType = typ
301
+ if not endsInNoReturn(a[^1]):
302
+ expectedType = typ
299
303
else:
300
304
a[^1] = semExprBranchScope(c, a[^1])
301
305
dec last
@@ -1145,7 +1149,8 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil
1145
1149
var last = x.len-1
1146
1150
x[last] = semExprBranchScope(c, x[last], expectedType)
1147
1151
typ = commonType(c, typ, x[last])
1148
- expectedType = typ
1152
+ if not endsInNoReturn(x[last]):
1153
+ expectedType = typ
1149
1154
of nkElifBranch:
1150
1155
if hasElse: invalidOrderOfBranches(x)
1151
1156
chckCovered = false
@@ -1154,13 +1159,15 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil
1154
1159
x[0] = forceBool(c, semExprWithType(c, x[0], expectedType = getSysType(c.graph, n.info, tyBool)))
1155
1160
x[1] = semExprBranch(c, x[1], expectedType = expectedType)
1156
1161
typ = commonType(c, typ, x[1])
1157
- expectedType = typ
1162
+ if not endsInNoReturn(x[1]):
1163
+ expectedType = typ
1158
1164
closeScope(c)
1159
1165
of nkElse:
1160
1166
checkSonsLen(x, 1, c.config)
1161
1167
x[0] = semExprBranchScope(c, x[0], expectedType)
1162
1168
typ = commonType(c, typ, x[0])
1163
- expectedType = typ
1169
+ if not endsInNoReturn(x[0]):
1170
+ expectedType = typ
1164
1171
if (chckCovered and covered == toCover(c, n[0].typ)) or hasElse:
1165
1172
message(c.config, x.info, warnUnreachableElse)
1166
1173
hasElse = true
0 commit comments