From fb6c8055683051283f6e094b4f3c2eea8c120207 Mon Sep 17 00:00:00 2001 From: metagn Date: Thu, 14 Mar 2024 13:23:09 +0300 Subject: [PATCH] propagate efWantStmt in semWhen (#23400) fixes #23399 The new case introduced in #21657 is triggered by `efWantStmt` but the `when` statement doesn't normally propagate this flag, so propagate it when the `semCheck` param in `semWhen` is true which happens when the `when` statement is `efWhenStmt` anyway. --- compiler/semexprs.nim | 7 ++++--- tests/modules/tmodulesymtype.nim | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index beb3719e8f..d39ec6b717 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2577,9 +2577,10 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = # If semCheck is set to false, ``when`` will return the verbatim AST of # the correct branch. Otherwise the AST will be passed through semStmt. result = nil + let flags = if semCheck: {efWantStmt} else: {} template setResult(e: untyped) = - if semCheck: result = semExpr(c, e) # do not open a new scope! + if semCheck: result = semExpr(c, e, flags) # do not open a new scope! else: result = e # Check if the node is "when nimvm" @@ -2605,7 +2606,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = checkSonsLen(it, 2, c.config) if whenNimvm: if semCheck: - it[1] = semExpr(c, it[1]) + it[1] = semExpr(c, it[1], flags) typ = commonType(c, typ, it[1].typ) result = n # when nimvm is not elimited until codegen else: @@ -2621,7 +2622,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = checkSonsLen(it, 1, c.config) if result == nil or whenNimvm: if semCheck: - it[0] = semExpr(c, it[0]) + it[0] = semExpr(c, it[0], flags) typ = commonType(c, typ, it[0].typ) if result == nil: result = it[0] diff --git a/tests/modules/tmodulesymtype.nim b/tests/modules/tmodulesymtype.nim index b1378ab698..d17c4cca44 100644 --- a/tests/modules/tmodulesymtype.nim +++ b/tests/modules/tmodulesymtype.nim @@ -13,3 +13,10 @@ proc foo() = sequtils foo() + +# issue #23399 +when isMainModule: + sequtils #[tt.Error + ^ expression has no type: sequtils]# + +discard