introduce precise string '[]', '[]=' accessors; fixes #8049 (#8817)

This commit is contained in:
Andreas Rumpf 2018-08-30 23:01:15 +02:00 • committed by GitHub
commit df4d5b77a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View file

@ -1391,8 +1391,8 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
n.sons[1] = semConstExpr(c, n.sons[1])
if skipTypes(n.sons[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in
{tyInt..tyInt64}:
var idx = getOrdValue(n.sons[1])
if idx >= 0 and idx < sonsLen(arr): n.typ = arr.sons[int(idx)]
let idx = getOrdValue(n.sons[1])
if idx >= 0 and idx < len(arr): n.typ = arr.sons[int(idx)]
else: localError(c.config, n.info, "invalid index value for tuple subscript")
result = n
else: