diff options
author | Araq <rumpf_a@web.de> | 2018-09-26 11:32:02 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-09-26 11:32:02 +0200 |
commit | 787687727afd3da891e60f1b145e2cbb56a21203 (patch) | |
tree | c2baa32ec9f0050b3c3f2b5e15aa33a5fd150918 | |
parent | 3d768738f8a5b444c61a1e01b1cfa0d2c51255c4 (diff) | |
download | Nim-787687727afd3da891e60f1b145e2cbb56a21203.tar.gz |
fixes #9076
-rw-r--r-- | compiler/ccgstmts.nim | 2 | ||||
-rw-r--r-- | compiler/semstmts.nim | 4 | ||||
-rw-r--r-- | tests/discard/tneedsdiscard_in_for.nim | 22 |
3 files changed, 26 insertions, 2 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 69e6558bb..b7846f605 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -1159,4 +1159,4 @@ proc genStmts(p: BProc, t: PNode) = if isPush: pushInfoContext(p.config, t.info) expr(p, t, a) if isPush: popInfoContext(p.config) - internalAssert p.config, a.k in {locNone, locTemp, locLocalVar} + internalAssert p.config, a.k in {locNone, locTemp, locLocalVar, locExpr} diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 75a4198a5..d5c5b7f86 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -114,7 +114,7 @@ const skipForDiscardable = {nkIfStmt, nkIfExpr, nkCaseStmt, nkOfBranch, nkElse, nkStmtListExpr, nkTryStmt, nkFinally, nkExceptBranch, nkElifBranch, nkElifExpr, nkElseExpr, nkBlockStmt, nkBlockExpr, - nkHiddenStdConv} + nkHiddenStdConv, nkHiddenDeref} proc implicitlyDiscardable(n: PNode): bool = var n = n @@ -601,6 +601,8 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = inc(c.p.nestedLoopCounter) openScope(c) n.sons[length-1] = semExprBranch(c, n.sons[length-1], flags) + if efInTypeof notin flags: + discardCheck(c, n.sons[length-1], flags) closeScope(c) dec(c.p.nestedLoopCounter) diff --git a/tests/discard/tneedsdiscard_in_for.nim b/tests/discard/tneedsdiscard_in_for.nim new file mode 100644 index 000000000..5658f4ba2 --- /dev/null +++ b/tests/discard/tneedsdiscard_in_for.nim @@ -0,0 +1,22 @@ +discard """ + line: 22 + errormsg: '''expression 'premultiply(app.gradient[i])' is of type 'Rgba8' and has to be discarded''' +""" + +# bug #9076 +type + Rgba8 = object + +proc premultiply*(c: var Rgba8): var Rgba8 = + discard + +type + App = ref object + gradient: seq[Rgba8] + +method onDraw(app: App) {.base.} = + var + width = 100'f64 + + for i in 0..<width.int: + app.gradient[i].premultiply() |