fixes #844
This commit is contained in:
parent
4b94aba6de
commit
47e4f9698c
4 changed files with 21 additions and 7 deletions
|
|
@ -42,7 +42,7 @@ type
|
||||||
|
|
||||||
TExprFlag* = enum
|
TExprFlag* = enum
|
||||||
efLValue, efWantIterator, efInTypeof, efWantStmt, efDetermineType,
|
efLValue, efWantIterator, efInTypeof, efWantStmt, efDetermineType,
|
||||||
efAllowDestructor
|
efAllowDestructor, efWantValue
|
||||||
TExprFlags* = set[TExprFlag]
|
TExprFlags* = set[TExprFlag]
|
||||||
|
|
||||||
PContext* = ref TContext
|
PContext* = ref TContext
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ proc semOperand(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result.typ = errorType(c)
|
result.typ = errorType(c)
|
||||||
|
|
||||||
proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semExpr(c, n, flags)
|
result = semExpr(c, n, flags+{efWantValue})
|
||||||
if result.isNil or result.kind == nkEmpty:
|
if result.isNil or result.kind == nkEmpty:
|
||||||
# do not produce another redundant error message:
|
# do not produce another redundant error message:
|
||||||
#raiseRecoverableError("")
|
#raiseRecoverableError("")
|
||||||
|
|
@ -1993,7 +1993,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semStaticExpr(c, n)
|
result = semStaticExpr(c, n)
|
||||||
of nkAsgn: result = semAsgn(c, n)
|
of nkAsgn: result = semAsgn(c, n)
|
||||||
of nkBlockStmt, nkBlockExpr: result = semBlock(c, n)
|
of nkBlockStmt, nkBlockExpr: result = semBlock(c, n)
|
||||||
of nkStmtList, nkStmtListExpr: result = semStmtList(c, n)
|
of nkStmtList, nkStmtListExpr: result = semStmtList(c, n, flags)
|
||||||
of nkRaiseStmt: result = semRaise(c, n)
|
of nkRaiseStmt: result = semRaise(c, n)
|
||||||
of nkVarSection: result = semVarOrLet(c, n, skVar)
|
of nkVarSection: result = semVarOrLet(c, n, skVar)
|
||||||
of nkLetSection: result = semVarOrLet(c, n, skLet)
|
of nkLetSection: result = semVarOrLet(c, n, skLet)
|
||||||
|
|
|
||||||
|
|
@ -1206,7 +1206,7 @@ proc usesResult(n: PNode): bool =
|
||||||
for c in n:
|
for c in n:
|
||||||
if usesResult(c): return true
|
if usesResult(c): return true
|
||||||
|
|
||||||
proc semStmtList(c: PContext, n: PNode): PNode =
|
proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# these must be last statements in a block:
|
# these must be last statements in a block:
|
||||||
const
|
const
|
||||||
LastBlockStmts = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt}
|
LastBlockStmts = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt}
|
||||||
|
|
@ -1247,12 +1247,14 @@ proc semStmtList(c: PContext, n: PNode): PNode =
|
||||||
if n.sons[i].typ == enforceVoidContext or usesResult(n.sons[i]):
|
if n.sons[i].typ == enforceVoidContext or usesResult(n.sons[i]):
|
||||||
voidContext = true
|
voidContext = true
|
||||||
n.typ = enforceVoidContext
|
n.typ = enforceVoidContext
|
||||||
if i != last or voidContext or c.inTypeClass > 0:
|
if i == last and efWantValue in flags:
|
||||||
|
n.typ = n.sons[i].typ
|
||||||
|
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
||||||
|
elif i != last or voidContext or c.inTypeClass > 0:
|
||||||
discardCheck(c, n.sons[i])
|
discardCheck(c, n.sons[i])
|
||||||
else:
|
else:
|
||||||
n.typ = n.sons[i].typ
|
n.typ = n.sons[i].typ
|
||||||
if not isEmptyType(n.typ):
|
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
||||||
n.kind = nkStmtListExpr
|
|
||||||
case n.sons[i].kind
|
case n.sons[i].kind
|
||||||
of nkVarSection, nkLetSection:
|
of nkVarSection, nkLetSection:
|
||||||
let (outer, inner) = insertDestructors(c, n.sons[i])
|
let (outer, inner) = insertDestructors(c, n.sons[i])
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,15 @@ proc semiProblem() =
|
||||||
if false: echo "aye"; echo "indeed"
|
if false: echo "aye"; echo "indeed"
|
||||||
|
|
||||||
semiProblem()
|
semiProblem()
|
||||||
|
|
||||||
|
|
||||||
|
# bug #844
|
||||||
|
|
||||||
|
import json
|
||||||
|
proc parseResponse(): PJsonNode =
|
||||||
|
result = % { "key1": % { "key2": % "value" } }
|
||||||
|
for key, val in result["key1"]:
|
||||||
|
var excMsg = key & "("
|
||||||
|
if (var n=result["key2"]; n != nil):
|
||||||
|
excMsg &= n.str
|
||||||
|
raise newException(ESynch, excMsg)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue