attempt to fix a bug concerning implicit type conversions in case statements
This commit is contained in:
parent
16adc837be
commit
a79acb58fc
4 changed files with 26 additions and 29 deletions
|
|
@ -146,6 +146,14 @@ proc IITablePut*(t: var TIITable, key, val: int)
|
||||||
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
|
proc skipConv*(n: PNode): PNode =
|
||||||
|
case n.kind
|
||||||
|
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
||||||
|
result = n.sons[0]
|
||||||
|
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||||
|
result = n.sons[1]
|
||||||
|
else: result = n
|
||||||
|
|
||||||
proc SameValue*(a, b: PNode): bool =
|
proc SameValue*(a, b: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
case a.kind
|
case a.kind
|
||||||
|
|
|
||||||
|
|
@ -249,43 +249,38 @@ proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
||||||
result = semIdentVis(c, kind, n, allowed)
|
result = semIdentVis(c, kind, n, allowed)
|
||||||
|
|
||||||
proc checkForOverlap(c: PContext, t, ex: PNode, branchIndex: int) =
|
proc checkForOverlap(c: PContext, t, ex: PNode, branchIndex: int) =
|
||||||
|
let ex = ex.skipConv
|
||||||
for i in countup(1, branchIndex - 1):
|
for i in countup(1, branchIndex - 1):
|
||||||
for j in countup(0, sonsLen(t.sons[i]) - 2):
|
for j in countup(0, sonsLen(t.sons[i]) - 2):
|
||||||
if overlap(t.sons[i].sons[j], ex):
|
if overlap(t.sons[i].sons[j].skipConv, ex):
|
||||||
LocalError(ex.info, errDuplicateCaseLabel)
|
LocalError(ex.info, errDuplicateCaseLabel)
|
||||||
|
|
||||||
proc semBranchExpr(c: PContext, t, e: PNode): PNode =
|
proc semBranchRange(c: PContext, t, a, b: PNode, covered: var biggestInt): PNode =
|
||||||
result = semConstExpr(c, e)
|
|
||||||
checkMinSonsLen(t, 1)
|
checkMinSonsLen(t, 1)
|
||||||
result = fitNode(c, t.sons[0].typ, result)
|
let ac = semConstExpr(c, a)
|
||||||
#if cmpTypes(t.sons[0].typ, result.typ) <= isConvertible:
|
let bc = semConstExpr(c, b)
|
||||||
# typeMismatch(result, t.sons[0].typ, result.typ)
|
let at = fitNode(c, t.sons[0].typ, ac)
|
||||||
|
let bt = fitNode(c, t.sons[0].typ, bc)
|
||||||
|
|
||||||
|
result = newNodeI(nkRange, a.info)
|
||||||
|
result.add(at)
|
||||||
|
result.add(bt)
|
||||||
|
if emptyRange(ac, bc): GlobalError(b.info, errRangeIsEmpty)
|
||||||
|
covered = covered + getOrdValue(bc) - getOrdValue(ac) + 1
|
||||||
|
|
||||||
proc SemCaseBranchRange(c: PContext, t, b: PNode,
|
proc SemCaseBranchRange(c: PContext, t, b: PNode,
|
||||||
covered: var biggestInt): PNode =
|
covered: var biggestInt): PNode =
|
||||||
checkSonsLen(b, 3)
|
checkSonsLen(b, 3)
|
||||||
result = newNodeI(nkRange, b.info)
|
result = semBranchRange(c, t, b.sons[1], b.sons[2], covered)
|
||||||
result.add(semBranchExpr(c, t, b.sons[1]))
|
|
||||||
result.add(semBranchExpr(c, t, b.sons[2]))
|
|
||||||
if emptyRange(result[0], result[1]): GlobalError(b.info, errRangeIsEmpty)
|
|
||||||
covered = covered + getOrdValue(result[1]) - getOrdValue(result[0]) + 1
|
|
||||||
|
|
||||||
proc semCaseBranchSetElem(c: PContext, t, b: PNode,
|
proc semCaseBranchSetElem(c: PContext, t, b: PNode,
|
||||||
covered: var biggestInt): PNode =
|
covered: var biggestInt): PNode =
|
||||||
if isRange(b):
|
if isRange(b):
|
||||||
checkSonsLen(b, 3)
|
checkSonsLen(b, 3)
|
||||||
result = newNodeI(nkRange, b.info)
|
result = semBranchRange(c, t, b.sons[1], b.sons[2], covered)
|
||||||
result.add(semBranchExpr(c, t, b.sons[1]))
|
|
||||||
result.add(semBranchExpr(c, t, b.sons[2]))
|
|
||||||
if emptyRange(result[0], result[1]): GlobalError(b.info, errRangeIsEmpty)
|
|
||||||
covered = covered + getOrdValue(result[1]) - getOrdValue(result[0]) + 1
|
|
||||||
elif b.kind == nkRange:
|
elif b.kind == nkRange:
|
||||||
checkSonsLen(b, 2)
|
checkSonsLen(b, 2)
|
||||||
result = newNodeI(nkRange, b.info)
|
result = semBranchRange(c, t, b.sons[0], b.sons[1], covered)
|
||||||
result.add(semBranchExpr(c, t, b.sons[0]))
|
|
||||||
result.add(semBranchExpr(c, t, b.sons[1]))
|
|
||||||
if emptyRange(result[0], result[1]): GlobalError(b.info, errRangeIsEmpty)
|
|
||||||
covered = covered + getOrdValue(result[1]) - getOrdValue(result[0]) + 1
|
|
||||||
else:
|
else:
|
||||||
result = fitNode(c, t.sons[0].typ, b)
|
result = fitNode(c, t.sons[0].typ, b)
|
||||||
inc(covered)
|
inc(covered)
|
||||||
|
|
|
||||||
|
|
@ -267,14 +267,6 @@ proc transformLoopBody(c: PTransf, n: PNode): PTransNode =
|
||||||
discard c.blockSyms.pop()
|
discard c.blockSyms.pop()
|
||||||
else:
|
else:
|
||||||
result = transform(c, n)
|
result = transform(c, n)
|
||||||
|
|
||||||
proc skipConv(n: PNode): PNode =
|
|
||||||
case n.kind
|
|
||||||
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
|
||||||
result = n.sons[0]
|
|
||||||
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
|
||||||
result = n.sons[1]
|
|
||||||
else: result = n
|
|
||||||
|
|
||||||
proc newTupleAccess(tup: PNode, i: int): PNode =
|
proc newTupleAccess(tup: PNode, i: int): PNode =
|
||||||
result = newNodeIT(nkBracketExpr, tup.info, tup.typ.sons[i])
|
result = newNodeIT(nkBracketExpr, tup.info, tup.typ.sons[i])
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -1,6 +1,7 @@
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
- fix bug #100 so that unittests work again
|
||||||
- ``=`` should be overloadable; requires specialization for ``=``
|
- ``=`` should be overloadable; requires specialization for ``=``
|
||||||
- fix remaining generics bugs
|
- fix remaining generics bugs
|
||||||
- fix remaining closure bugs:
|
- fix remaining closure bugs:
|
||||||
|
|
@ -99,6 +100,7 @@ version 0.9.XX
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- provide more up to date OpenGL headers
|
||||||
- wrappers for mongodb; poppler; libharu
|
- wrappers for mongodb; poppler; libharu
|
||||||
- suffix trees
|
- suffix trees
|
||||||
- locale support; i18n module
|
- locale support; i18n module
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue