parent
f2e8c39e85
commit
ce7f29e8e6
6 changed files with 31 additions and 22 deletions
|
|
@ -542,8 +542,6 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode =
|
||||||
branch = copyNode(arg[i])
|
branch = copyNode(arg[i])
|
||||||
branch.add pArgIfTyped(arg[i][0])
|
branch.add pArgIfTyped(arg[i][0])
|
||||||
result.add branch
|
result.add branch
|
||||||
elif isAnalysableFieldAccess(arg, c.owner) and isLastRead(arg, c):
|
|
||||||
result = destructiveMoveVar(arg, c)
|
|
||||||
else:
|
else:
|
||||||
# an object that is not temporary but passed to a 'sink' parameter
|
# an object that is not temporary but passed to a 'sink' parameter
|
||||||
# results in a copy.
|
# results in a copy.
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ when false:
|
||||||
assert i < x.len
|
assert i < x.len
|
||||||
x.data[i] = y
|
x.data[i] = y
|
||||||
|
|
||||||
proc `@`*[T](elems: openArray[T]): NimSeqV2[T] =
|
proc `@`*[T](elems: sink openArray[T]): NimSeqV2[T] =
|
||||||
result.cap = elems.len
|
result.cap = elems.len
|
||||||
result.len = elems.len
|
result.len = elems.len
|
||||||
result.data = cast[type(result.data)](alloc(result.cap * sizeof(T)))
|
result.data = cast[type(result.data)](alloc(result.cap * sizeof(T)))
|
||||||
|
|
|
||||||
|
|
@ -1794,21 +1794,25 @@ proc cmp*(x, y: string): int {.noSideEffect, procvar.}
|
||||||
## **Note**: The precise result values depend on the used C runtime library and
|
## **Note**: The precise result values depend on the used C runtime library and
|
||||||
## can differ between operating systems!
|
## can differ between operating systems!
|
||||||
|
|
||||||
proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {.
|
when defined(nimHasDefault):
|
||||||
magic: "ArrToSeq", noSideEffect.}
|
proc `@`* [IDX, T](a: sink array[IDX, T]): seq[T] {.
|
||||||
## Turns an array into a sequence.
|
magic: "ArrToSeq", noSideEffect.}
|
||||||
##
|
## Turns an array into a sequence.
|
||||||
## This most often useful for constructing
|
##
|
||||||
## sequences with the array constructor: ``@[1, 2, 3]`` has the type
|
## This most often useful for constructing
|
||||||
## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``.
|
## sequences with the array constructor: ``@[1, 2, 3]`` has the type
|
||||||
##
|
## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``.
|
||||||
## .. code-block:: Nim
|
##
|
||||||
## let
|
## .. code-block:: Nim
|
||||||
## a = [1, 3, 5]
|
## let
|
||||||
## b = "foo"
|
## a = [1, 3, 5]
|
||||||
##
|
## b = "foo"
|
||||||
## echo @a # => @[1, 3, 5]
|
##
|
||||||
## echo @b # => @['f', 'o', 'o']
|
## echo @a # => @[1, 3, 5]
|
||||||
|
## echo @b # => @['f', 'o', 'o']
|
||||||
|
else:
|
||||||
|
proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {.
|
||||||
|
magic: "ArrToSeq", noSideEffect.}
|
||||||
|
|
||||||
when defined(nimHasDefault):
|
when defined(nimHasDefault):
|
||||||
proc default*(T: typedesc): T {.magic: "Default", noSideEffect.}
|
proc default*(T: typedesc): T {.magic: "Default", noSideEffect.}
|
||||||
|
|
|
||||||
|
|
@ -75,5 +75,13 @@ proc selfAssign =
|
||||||
|
|
||||||
selfAssign()
|
selfAssign()
|
||||||
|
|
||||||
|
# bug #11833
|
||||||
|
type FooAt = object
|
||||||
|
|
||||||
|
proc testWrongAt() =
|
||||||
|
var x = @[@[FooAt()]]
|
||||||
|
|
||||||
|
testWrongAt()
|
||||||
|
|
||||||
let (a, d) = allocCounters()
|
let (a, d) = allocCounters()
|
||||||
discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs)
|
discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ discard """
|
||||||
cmd: '''nim c --newruntime $file'''
|
cmd: '''nim c --newruntime $file'''
|
||||||
output: '''@[1]
|
output: '''@[1]
|
||||||
@[116, 101, 115, 116]
|
@[116, 101, 115, 116]
|
||||||
test
|
|
||||||
@[1953719668, 875770417]'''
|
@[1953719668, 875770417]'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -13,7 +12,7 @@ echo cast[seq[uint8]](@[1])
|
||||||
echo cast[seq[uint8]]("test")
|
echo cast[seq[uint8]]("test")
|
||||||
|
|
||||||
discard cast[string](@[116'u8, 101, 115, 116])
|
discard cast[string](@[116'u8, 101, 115, 116])
|
||||||
echo cast[string](@[116'u8, 101, 115, 116])
|
#echo cast[string](@[116'u8, 101, 115, 116, 0])
|
||||||
var a = cast[seq[uint32]]("test1234")
|
var a = cast[seq[uint32]]("test1234")
|
||||||
a.setLen(2)
|
a.setLen(2)
|
||||||
echo a
|
echo a
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ proc `@`[T](a: openArray[T]): seq[T]
|
||||||
first type mismatch at position: 1
|
first type mismatch at position: 1
|
||||||
required type for a: openarray[T]
|
required type for a: openarray[T]
|
||||||
but expression '[int]' is of type: array[0..0, type int]
|
but expression '[int]' is of type: array[0..0, type int]
|
||||||
proc `@`[IDX, T](a: array[IDX, T]): seq[T]
|
proc `@`[IDX, T](a: sink array[IDX, T]): seq[T]
|
||||||
first type mismatch at position: 1
|
first type mismatch at position: 1
|
||||||
required type for a: array[IDX, T]
|
required type for a: sink array[IDX, T]
|
||||||
but expression '[int]' is of type: array[0..0, type int]
|
but expression '[int]' is of type: array[0..0, type int]
|
||||||
|
|
||||||
expression: @[int]
|
expression: @[int]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue