This commit is contained in:
Yuriy Glukhov 2019-05-29 18:11:03 +08:00 • committed by Andreas Rumpf
commit 6904f323aa
2 changed files with 30 additions and 28 deletions

View file

@ -3834,7 +3834,6 @@ template `^^`(s, i: untyped): untyped =
template `[]`*(s: string; i: int): char = arrGet(s, i) template `[]`*(s: string; i: int): char = arrGet(s, i)
template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val) template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val)
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.
## Returns the inclusive range `[s[x.a], s[x.b]]`: ## Returns the inclusive range `[s[x.a], s[x.b]]`:

View file

@ -11,3 +11,6 @@ proc printf(frmt: cstring) {.varargs, header: "<stdio.h>", cdecl.}
var x = 0 var x = 0
inc x inc x
printf("hi %ld\n", x+4777) printf("hi %ld\n", x+4777)
proc substr(a: string): string = a[0 .. 3] # This should compile. See #9762
const a = substr("foobar")