Merge branch 'devel' into araq-better-docgen
This commit is contained in:
commit
5709736e82
27 changed files with 383 additions and 160 deletions
|
|
@ -4,6 +4,9 @@ B0
|
|||
B1
|
||||
B2
|
||||
B3
|
||||
B4
|
||||
B5
|
||||
B6
|
||||
'''
|
||||
"""
|
||||
|
||||
|
|
@ -14,6 +17,14 @@ template crossCheck(ty: untyped, exp: untyped) =
|
|||
echo "Got ", ct
|
||||
echo "Expected ", rt
|
||||
|
||||
template add1(x: uint8): untyped = x + 1
|
||||
template add1(x: uint16): untyped = x + 1
|
||||
template add1(x: uint32): untyped = x + 1
|
||||
|
||||
template sub1(x: uint8): untyped = x - 1
|
||||
template sub1(x: uint16): untyped = x - 1
|
||||
template sub1(x: uint32): untyped = x - 1
|
||||
|
||||
block:
|
||||
when true:
|
||||
echo "B0"
|
||||
|
|
@ -34,10 +45,34 @@ block:
|
|||
crossCheck(uint64, (-1).uint64 + 5'u64)
|
||||
|
||||
echo "B3"
|
||||
crossCheck(int8, 0'u8 - 5'u8)
|
||||
crossCheck(int16, 0'u16 - 5'u16)
|
||||
crossCheck(int32, 0'u32 - 5'u32)
|
||||
crossCheck(int64, 0'u64 - 5'u64)
|
||||
doAssert $sub1(0'u8) == "255"
|
||||
doAssert $sub1(0'u16) == "65535"
|
||||
doAssert $sub1(0'u32) == "4294967295"
|
||||
|
||||
echo "B4"
|
||||
doAssert $add1(255'u8) == "0"
|
||||
doAssert $add1(65535'u16) == "0"
|
||||
doAssert $add1(4294967295'u32) == "0"
|
||||
|
||||
echo "B5"
|
||||
crossCheck(int32, high(int32))
|
||||
crossCheck(int32, high(int32).int32)
|
||||
crossCheck(int32, low(int32))
|
||||
crossCheck(int32, low(int32).int32)
|
||||
crossCheck(int64, high(int8).int16.int32.int64)
|
||||
crossCheck(int64, low(int8).int16.int32.int64)
|
||||
|
||||
echo "B6"
|
||||
crossCheck(int64, 0xFFFFFFFFFFFFFFFF'u64)
|
||||
crossCheck(int32, 0xFFFFFFFFFFFFFFFF'u64)
|
||||
crossCheck(int16, 0xFFFFFFFFFFFFFFFF'u64)
|
||||
crossCheck(int8 , 0xFFFFFFFFFFFFFFFF'u64)
|
||||
|
||||
# Out of range conversion, caught for `let`s only
|
||||
# crossCheck(int8, 0'u8 - 5'u8)
|
||||
# crossCheck(int16, 0'u16 - 5'u16)
|
||||
# crossCheck(int32, 0'u32 - 5'u32)
|
||||
# crossCheck(int64, 0'u64 - 5'u64)
|
||||
|
||||
# crossCheck(int8, 0'u16 - 129'u16)
|
||||
# crossCheck(uint8, 0'i16 + 257'i16)
|
||||
|
|
|
|||
19
tests/assert/tfailedassert_stacktrace.nim
Normal file
19
tests/assert/tfailedassert_stacktrace.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
discard """
|
||||
output: '''
|
||||
tfailedassert_stacktrace.nim(16) tfailedassert_stacktrace
|
||||
tfailedassert_stacktrace.nim(15) foo
|
||||
system.nim(3778) failedAssertImpl
|
||||
system.nim(3771) raiseAssert
|
||||
system.nim(2818) sysFatal
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
|
||||
try:
|
||||
proc foo() =
|
||||
assert(false)
|
||||
foo()
|
||||
except AssertionError:
|
||||
let e = getCurrentException()
|
||||
echo e.getStackTrace
|
||||
8
tests/ccgbugs/tborrowmagic.nim
Normal file
8
tests/ccgbugs/tborrowmagic.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
type
|
||||
Bytes = distinct seq[byte]
|
||||
|
||||
proc add(x: var Bytes; b: byte) {.borrow.}
|
||||
var x = @[].Bytes
|
||||
x.add(42)
|
||||
let base = cast[seq[byte]](x)
|
||||
doAssert base.len == 1 and base[0] == 42
|
||||
8
tests/ccgbugs/thtiobj.nim
Normal file
8
tests/ccgbugs/thtiobj.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
discard """
|
||||
targets: "c cpp"
|
||||
"""
|
||||
|
||||
import typeinfo
|
||||
|
||||
var x = ""
|
||||
discard (getPointer(toAny(x)))
|
||||
7
tests/js/t7534.nim
Normal file
7
tests/js/t7534.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
proc f(x: int): int =
|
||||
result = case x
|
||||
of 1: 2
|
||||
elif x == 2: 3
|
||||
else: 1
|
||||
|
||||
doAssert 2 == f(f(f(f(1))))
|
||||
12
tests/js/t8914.nim
Normal file
12
tests/js/t8914.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
output: '''
|
||||
@[42]
|
||||
@[24, 42]
|
||||
'''
|
||||
"""
|
||||
|
||||
var x = @[42,4242]
|
||||
x.delete(1)
|
||||
echo x
|
||||
x.insert(24)
|
||||
echo x
|
||||
4
tests/js/taddnilstr.nim
Normal file
4
tests/js/taddnilstr.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var x = "foo".cstring
|
||||
var y: string
|
||||
add(y, x)
|
||||
doAssert y == "foo"
|
||||
5
tests/js/tstrconcat.nim
Normal file
5
tests/js/tstrconcat.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var x: string
|
||||
var y = "foo"
|
||||
add(x, y)
|
||||
y[0] = 'm'
|
||||
doAssert y == "moo" and x == "foo"
|
||||
63
tests/macros/tcollect.nim
Normal file
63
tests/macros/tcollect.nim
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
discard """
|
||||
output: '''@[2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4]
|
||||
@[0, 1, 2, 3]'''
|
||||
"""
|
||||
|
||||
const data = [1,2,3,4,5,6]
|
||||
|
||||
import macros
|
||||
|
||||
macro collect(body): untyped =
|
||||
# analyse the body, find the deepest expression 'it' and replace it via
|
||||
# 'result.add it'
|
||||
let res = genSym(nskVar, "collectResult")
|
||||
|
||||
when false:
|
||||
proc detectForLoopVar(n: NimNode): NimNode =
|
||||
if n.kind == nnkForStmt:
|
||||
result = n[0]
|
||||
else:
|
||||
for x in n:
|
||||
result = detectForLoopVar(x)
|
||||
if result != nil: return result
|
||||
return nil
|
||||
|
||||
proc t(n, res: NimNode): NimNode =
|
||||
case n.kind
|
||||
of nnkStmtList, nnkStmtListExpr, nnkBlockStmt, nnkBlockExpr,
|
||||
nnkWhileStmt,
|
||||
nnkForStmt, nnkIfExpr, nnkIfStmt, nnkTryStmt, nnkCaseStmt,
|
||||
nnkElifBranch, nnkElse, nnkElifExpr:
|
||||
result = copyNimTree(n)
|
||||
if n.len >= 1:
|
||||
result[^1] = t(n[^1], res)
|
||||
else:
|
||||
if true: #n == it:
|
||||
template adder(res, it) =
|
||||
res.add it
|
||||
result = getAst adder(res, n)
|
||||
else:
|
||||
result = n
|
||||
|
||||
when false:
|
||||
let it = detectForLoopVar(body)
|
||||
if it == nil: error("no for loop in body", body)
|
||||
|
||||
let v = newTree(nnkVarSection,
|
||||
newTree(nnkIdentDefs, res, newTree(nnkBracketExpr, bindSym"seq",
|
||||
newCall(bindSym"type", body)), newEmptyNode()))
|
||||
|
||||
result = newTree(nnkStmtListExpr, v, t(body, res), res)
|
||||
#echo repr result
|
||||
|
||||
let stuff = collect:
|
||||
var i = -1
|
||||
while i < 4:
|
||||
inc i
|
||||
for it in data:
|
||||
if it < 5 and it > 1:
|
||||
it
|
||||
|
||||
echo stuff
|
||||
|
||||
echo collect(for i in 0..3: i)
|
||||
10
tests/seq/t7346.nim
Normal file
10
tests/seq/t7346.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
when not defined(nimNewRuntime):
|
||||
{.error: "This bug could only be reproduced with --newruntime".}
|
||||
|
||||
type
|
||||
Obj = object
|
||||
a: int
|
||||
|
||||
proc `=`(a: var Obj, b: Obj) = discard
|
||||
|
||||
let a: seq[Obj] = @[]
|
||||
7
tests/typerel/t8905.nim
Normal file
7
tests/typerel/t8905.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
type
|
||||
Foo[T] = distinct seq[T]
|
||||
Bar[T] = object
|
||||
|
||||
proc newFoo[T](): Foo[T] = Foo[T](newSeq[T]())
|
||||
|
||||
var x = newFoo[Bar[int]]()
|
||||
10
tests/types/t6969.nim
Normal file
10
tests/types/t6969.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
discard """
|
||||
errormsg: "invalid type: 'object' for var"
|
||||
line: 6
|
||||
"""
|
||||
|
||||
var a: object a: int
|
||||
# or
|
||||
var b: ref object a: int
|
||||
# or
|
||||
var c: ptr object a: int
|
||||
1
tests/types/t7581.nim
Normal file
1
tests/types/t7581.nim
Normal file
|
|
@ -0,0 +1 @@
|
|||
discard int -1
|
||||
Loading…
Add table
Add a link
Reference in a new issue