parent
dfdf8e58c7
commit
df4d5b77a1
4 changed files with 33 additions and 3 deletions
|
|
@ -1391,8 +1391,8 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
n.sons[1] = semConstExpr(c, n.sons[1])
|
n.sons[1] = semConstExpr(c, n.sons[1])
|
||||||
if skipTypes(n.sons[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in
|
if skipTypes(n.sons[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in
|
||||||
{tyInt..tyInt64}:
|
{tyInt..tyInt64}:
|
||||||
var idx = getOrdValue(n.sons[1])
|
let idx = getOrdValue(n.sons[1])
|
||||||
if idx >= 0 and idx < sonsLen(arr): n.typ = arr.sons[int(idx)]
|
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")
|
else: localError(c.config, n.info, "invalid index value for tuple subscript")
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -2132,6 +2132,10 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
|
||||||
styleCheckUse(arg.info, arg.sons[best].sym)
|
styleCheckUse(arg.info, arg.sons[best].sym)
|
||||||
result = paramTypesMatchAux(m, f, arg.sons[best].typ, arg.sons[best],
|
result = paramTypesMatchAux(m, f, arg.sons[best].typ, arg.sons[best],
|
||||||
argOrig)
|
argOrig)
|
||||||
|
when false:
|
||||||
|
if m.calleeSym != nil and m.calleeSym.name.s == "[]":
|
||||||
|
echo m.c.config $ arg.info, " for ", m.calleeSym.name.s, " ", m.c.config $ m.calleeSym.info
|
||||||
|
writeMatches(m)
|
||||||
|
|
||||||
proc setSon(father: PNode, at: int, son: PNode) =
|
proc setSon(father: PNode, at: int, son: PNode) =
|
||||||
let oldLen = father.len
|
let oldLen = father.len
|
||||||
|
|
@ -2380,6 +2384,11 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||||
if m.magic in {mArrGet, mArrPut}:
|
if m.magic in {mArrGet, mArrPut}:
|
||||||
m.state = csMatch
|
m.state = csMatch
|
||||||
m.call = n
|
m.call = n
|
||||||
|
# Note the following doesn't work as it would produce ambiguities.
|
||||||
|
# Instead we patch system.nim, see bug #8049.
|
||||||
|
when false:
|
||||||
|
inc m.genericMatches
|
||||||
|
inc m.exactMatches
|
||||||
return
|
return
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
matchesAux(c, n, nOrig, m, marker)
|
matchesAux(c, n, nOrig, m, marker)
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,12 @@ when defined(nimArrIdx):
|
||||||
proc `[]=`*[I: Ordinal;T,S](a: T; i: I;
|
proc `[]=`*[I: Ordinal;T,S](a: T; i: I;
|
||||||
x: S) {.noSideEffect, magic: "ArrPut".}
|
x: S) {.noSideEffect, magic: "ArrPut".}
|
||||||
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
||||||
|
|
||||||
|
proc arrGet[I: Ordinal;T](a: T; i: I): T {.
|
||||||
|
noSideEffect, magic: "ArrGet".}
|
||||||
|
proc arrPut[I: Ordinal;T,S](a: T; i: I;
|
||||||
|
x: S) {.noSideEffect, magic: "ArrPut".}
|
||||||
|
|
||||||
when defined(nimNewRuntime):
|
when defined(nimNewRuntime):
|
||||||
proc `=destroy`*[T](x: var T) {.inline, magic: "Asgn".} =
|
proc `=destroy`*[T](x: var T) {.inline, magic: "Asgn".} =
|
||||||
## generic `destructor`:idx: implementation that can be overriden.
|
## generic `destructor`:idx: implementation that can be overriden.
|
||||||
|
|
@ -3526,6 +3532,9 @@ template spliceImpl(s, a, L, b: untyped): untyped =
|
||||||
template `^^`(s, i: untyped): untyped =
|
template `^^`(s, i: untyped): untyped =
|
||||||
(when i is BackwardsIndex: s.len - int(i) else: int(i))
|
(when i is BackwardsIndex: s.len - int(i) else: int(i))
|
||||||
|
|
||||||
|
template `[]`*(s: string; i: int): char = arrGet(s, i)
|
||||||
|
template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val)
|
||||||
|
|
||||||
when hasAlloc or defined(nimscript):
|
when hasAlloc or defined(nimscript):
|
||||||
proc `[]`*[T, U](s: string, x: HSlice[T, U]): string {.inline.} =
|
proc `[]`*[T, U](s: string, x: HSlice[T, U]): string {.inline.} =
|
||||||
## slice operation for strings.
|
## slice operation for strings.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''0
|
output: '''0
|
||||||
0'''
|
0
|
||||||
|
bc
|
||||||
|
bcdefg'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# test another strange bug ... (I hate this compiler; it is much too buggy!)
|
# test another strange bug ... (I hate this compiler; it is much too buggy!)
|
||||||
|
|
@ -29,3 +31,13 @@ var
|
||||||
|
|
||||||
echo obj.s1[0]
|
echo obj.s1[0]
|
||||||
echo obj.s1[0u]
|
echo obj.s1[0u]
|
||||||
|
|
||||||
|
|
||||||
|
# bug #8049
|
||||||
|
|
||||||
|
when true:
|
||||||
|
type ustring* = distinct string
|
||||||
|
converter toUString*(s: string): ustring = ustring(s)
|
||||||
|
proc `[]`*(s: ustring, i: int): ustring = s
|
||||||
|
echo "abcdefgh"[1..2]
|
||||||
|
echo "abcdefgh"[1..^2]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue