forked from nim-lang/Nim
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix nim-lang#9872: setLen now works properly at CT [backport]
(cherry picked from commit f838b1e)
- Loading branch information
1 parent
28946ed
commit c16fa63
Showing
2 changed files
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type Foo = object | ||
index: int | ||
|
||
block: | ||
proc fun[T]() = | ||
var foo: T | ||
var n = 10 | ||
|
||
var foos: seq[T] | ||
foos.setLen n | ||
|
||
n.inc | ||
foos.setLen n | ||
|
||
for i in 0 ..< n: | ||
let temp = foos[i] | ||
when T is object: | ||
doAssert temp.index == 0 | ||
when T is ref object: | ||
doAssert temp == nil | ||
doAssert temp == foo | ||
|
||
static: | ||
fun[Foo]() | ||
fun[int]() | ||
fun[float]() | ||
fun[string]() | ||
fun[(int, string)]() | ||
fun[ref Foo]() | ||
fun[seq[int]]() |