fixes a regression about indexing into UncheckedArray

This commit is contained in:
Andreas Rumpf 2018-10-16 20:09:00 +02:00
commit 0d48bafcf0
2 changed files with 16 additions and 1 deletions

View file

@ -1358,7 +1358,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
case arr.kind case arr.kind
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, of tyArray, tyOpenArray, tyVarargs, tySequence, tyString,
tyCString, tyUncheckedArray: tyCString:
if n.len != 2: return nil if n.len != 2: return nil
n.sons[0] = makeDeref(n.sons[0]) n.sons[0] = makeDeref(n.sons[0])
for i in countup(1, sonsLen(n) - 1): for i in countup(1, sonsLen(n) - 1):
@ -1371,6 +1371,17 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = n result = n
result.typ = elemType(arr) result.typ = elemType(arr)
#GlobalError(n.info, errIndexTypesDoNotMatch) #GlobalError(n.info, errIndexTypesDoNotMatch)
of tyUncheckedArray:
if n.len != 2: return nil
n.sons[0] = makeDeref(n.sons[0])
for i in countup(1, sonsLen(n) - 1):
n.sons[i] = semExprWithType(c, n.sons[i],
flags*{efInTypeof, efDetermineType})
# index into unchecked array must be some integer type:
if n.sons[1].typ.skipTypes(abstractRange-{tyDistinct}).kind in
{tyInt..tyInt64, tyUInt..tyUInt64}:
result = n
result.typ = elemType(arr)
of tyTypeDesc: of tyTypeDesc:
# The result so far is a tyTypeDesc bound # The result so far is a tyTypeDesc bound
# a tyGenericBody. The line below will substitute # a tyGenericBody. The line below will substitute

View file

@ -532,3 +532,7 @@ block t7818:
doAssert(testOpenArray(@[u.addr, v.addr, w.addr]) == "123") doAssert(testOpenArray(@[u.addr, v.addr, w.addr]) == "123")
doAssert(testOpenArray(@[w.addr, u.addr, v.addr]) == "312") doAssert(testOpenArray(@[w.addr, u.addr, v.addr]) == "312")
# regression regarding unchecked array indexing:
proc foo(x: ptr UncheckedArray[int]; idx: uint64) =
echo x[idx]