Closes #6083, closes #6086, closes #6379 (#6392)

This commit is contained in:
Daniil Yarancev
2017-09-16 23:54:32 +03:00
committed by Andreas Rumpf
parent 5b8f33a905
commit ae7fe5087f

View File

@@ -1,16 +1,66 @@
# bug #4462
import macros
proc foo(t: typedesc) {.compileTime.} =
echo getType(t).treeRepr
block:
proc foo(t: typedesc) {.compileTime.} =
assert sameType(getType(t), getType(int))
static:
foo(int)
static:
foo(int)
# #4412
proc default[T](t: typedesc[T]): T {.inline.} = discard
block:
proc default[T](t: typedesc[T]): T {.inline.} = discard
static:
var x = default(type(0))
# #6379
static:
var x = default(type(0))
import algorithm
var numArray = [1, 2, 3, 4, -1]
numArray.sort(cmp)
assert numArray == [-1, 1, 2, 3, 4]
var str = "cba"
str.sort(cmp)
assert str == "abc"
# #6086
import math, sequtils, future
block:
proc f: int =
toSeq(10..<10_000).filter(
a => a == ($a).map(
d => (d.ord-'0'.ord).int^4
).sum
).sum
var a = f()
const b = f()
assert a == b
block:
proc f(): seq[char] =
result = "hello".map(proc(x: char): char = x)
var runTime = f()
const compTime = f()
assert runTime == compTime
# #6083
block:
proc abc(): seq[int] =
result = @[0]
result.setLen(2)
var tmp: int
for i in 0 .. <2:
inc tmp
result[i] = tmp
const fact1000 = abc()
assert fact1000 == @[1, 2]