fix https://github.com/nim-lang/RFCs/issues/311 remove unary slice (#16714)
This commit is contained in:
parent
3b80f0dc8e
commit
ad67bcf379
5 changed files with 9 additions and 16 deletions
|
|
@ -112,7 +112,7 @@ proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int
|
||||||
if ident[^1] == '=' and ident[0] in linter.Letters:
|
if ident[^1] == '=' and ident[0] in linter.Letters:
|
||||||
if sourceIdent != "=":
|
if sourceIdent != "=":
|
||||||
result = 0
|
result = 0
|
||||||
elif sourceIdent.len > ident.len and sourceIdent[..ident.high] == ident:
|
elif sourceIdent.len > ident.len and sourceIdent[0..ident.high] == ident:
|
||||||
result = ident.len
|
result = ident.len
|
||||||
elif sourceIdent != ident:
|
elif sourceIdent != ident:
|
||||||
result = 0
|
result = 0
|
||||||
|
|
|
||||||
|
|
@ -510,14 +510,6 @@ proc `..`*[T, U](a: sink T, b: sink U): HSlice[T, U] {.noSideEffect, inline, mag
|
||||||
## echo a[2 .. 3] # @[30, 40]
|
## echo a[2 .. 3] # @[30, 40]
|
||||||
result = HSlice[T, U](a: a, b: b)
|
result = HSlice[T, U](a: a, b: b)
|
||||||
|
|
||||||
proc `..`*[T](b: sink T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
|
|
||||||
## Unary `slice`:idx: operator that constructs an interval `[default(int), b]`.
|
|
||||||
##
|
|
||||||
## .. code-block:: Nim
|
|
||||||
## let a = [10, 20, 30, 40, 50]
|
|
||||||
## echo a[.. 2] # @[10, 20, 30]
|
|
||||||
result = HSlice[int, T](a: 0, b: b)
|
|
||||||
|
|
||||||
when defined(hotCodeReloading):
|
when defined(hotCodeReloading):
|
||||||
{.pragma: hcrInline, inline.}
|
{.pragma: hcrInline, inline.}
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ proc findMainFile(dir: string): string =
|
||||||
var nimFiles = 0
|
var nimFiles = 0
|
||||||
for kind, file in os.walkDir(dir):
|
for kind, file in os.walkDir(dir):
|
||||||
if kind == pcFile:
|
if kind == pcFile:
|
||||||
if file.endsWith(cfgExt): return file[ .. ^(cfgExt.len+1)] & ".nim"
|
if file.endsWith(cfgExt): return file[0..^(cfgExt.len+1)] & ".nim"
|
||||||
elif file.endsWith(".nim"):
|
elif file.endsWith(".nim"):
|
||||||
if result.len == 0: result = file
|
if result.len == 0: result = file
|
||||||
inc nimFiles
|
inc nimFiles
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ block tableconstr:
|
||||||
# NEW:
|
# NEW:
|
||||||
doAssert 56 in 50..100
|
doAssert 56 in 50..100
|
||||||
|
|
||||||
doAssert 56 in ..60
|
doAssert 56 in 0..60
|
||||||
|
|
||||||
|
|
||||||
block ttables2:
|
block ttables2:
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,9 @@ verichtetd
|
||||||
|
|
||||||
# Test the new slices.
|
# Test the new slices.
|
||||||
|
|
||||||
import strutils
|
|
||||||
|
|
||||||
var mystr = "Abgrund"
|
var mystr = "Abgrund"
|
||||||
mystr[..1] = "Zu"
|
# mystr[..1] = "Zu" # deprecated
|
||||||
|
mystr[0..1] = "Zu"
|
||||||
|
|
||||||
mystr[4..4] = "5"
|
mystr[4..4] = "5"
|
||||||
|
|
||||||
|
|
@ -23,7 +22,8 @@ type
|
||||||
|
|
||||||
var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6]
|
var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6]
|
||||||
myarr[e1..e3] = myarr[e4..e6]
|
myarr[e1..e3] = myarr[e4..e6]
|
||||||
myarr[..e3] = myarr[e4..e6]
|
# myarr[..e3] = myarr[e4..e6] # deprecated
|
||||||
|
myarr[0..e3] = myarr[e4..e6]
|
||||||
|
|
||||||
for x in items(myarr): stdout.write(x)
|
for x in items(myarr): stdout.write(x)
|
||||||
echo()
|
echo()
|
||||||
|
|
@ -46,7 +46,8 @@ echo mystr
|
||||||
mystr[4..4] = "u"
|
mystr[4..4] = "u"
|
||||||
|
|
||||||
# test full replacement
|
# test full replacement
|
||||||
mystr[.. ^2] = "egerichtet"
|
# mystr[.. ^2] = "egerichtet" # deprecated
|
||||||
|
mystr[0 .. ^2] = "egerichtet"
|
||||||
|
|
||||||
echo mystr
|
echo mystr
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue