mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 20:17:42 +00:00
fixes #23775
This commit is contained in:
@@ -653,7 +653,7 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false,
|
||||
for j in 0 ..< it.len-1:
|
||||
branch[j] = copyTree(it[j])
|
||||
var ofScope = nestedScope(s, it.lastSon)
|
||||
branch[^1] = if it[^1].typ.isEmptyType or willProduceStmt:
|
||||
branch[^1] = if n.typ.isEmptyType or it[^1].typ.isEmptyType or willProduceStmt:
|
||||
processScope(c, ofScope, maybeVoid(it[^1], ofScope))
|
||||
else:
|
||||
processScopeExpr(c, ofScope, it[^1], processCall, tmpFlags)
|
||||
@@ -701,7 +701,7 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false,
|
||||
#Condition needs to be destroyed outside of the condition/branch scope
|
||||
branch[0] = p(it[0], c, s, normal)
|
||||
|
||||
branch[^1] = if it[^1].typ.isEmptyType or willProduceStmt:
|
||||
branch[^1] = if n.typ.isEmptyType or it[^1].typ.isEmptyType or willProduceStmt:
|
||||
processScope(c, branchScope, maybeVoid(it[^1], branchScope))
|
||||
else:
|
||||
processScopeExpr(c, branchScope, it[^1], processCall, tmpFlags)
|
||||
|
||||
@@ -283,6 +283,7 @@ proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) =
|
||||
if implicitlyDiscardable(result):
|
||||
var n = newNodeI(nkDiscardStmt, result.info, 1)
|
||||
n[0] = result
|
||||
# notes that it doesn't transform nodes into discard statements
|
||||
elif result.typ.kind != tyError and c.config.cmd != cmdInteractive:
|
||||
if result.typ.kind == tyNone:
|
||||
localError(c.config, result.info, "expression has no type: " &
|
||||
|
||||
@@ -140,3 +140,27 @@ block: # issue #14665
|
||||
continue
|
||||
inc i
|
||||
test()
|
||||
|
||||
block: # bug #23775
|
||||
proc retInt(): int {.discardable.} =
|
||||
42
|
||||
|
||||
proc retString(): string {.discardable.} =
|
||||
"text"
|
||||
|
||||
type
|
||||
Enum = enum
|
||||
A, B, C, D
|
||||
|
||||
proc doStuff(msg: Enum) =
|
||||
case msg:
|
||||
of A:
|
||||
retString()
|
||||
of B:
|
||||
retInt()
|
||||
of C:
|
||||
discard retString()
|
||||
else:
|
||||
let _ = retString()
|
||||
|
||||
doStuff(C)
|
||||
|
||||
Reference in New Issue
Block a user