mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 10:13:56 +00:00
Merge ../Nim into devel
This commit is contained in:
47
tests/destructor/tdestructor3.nim
Normal file
47
tests/destructor/tdestructor3.nim
Normal file
@@ -0,0 +1,47 @@
|
||||
discard """
|
||||
output: '''assign
|
||||
destroy
|
||||
destroy
|
||||
destroy Foo: 5
|
||||
5
|
||||
destroy Foo: 123
|
||||
123'''
|
||||
"""
|
||||
|
||||
# bug #2821
|
||||
{.experimental.}
|
||||
|
||||
type T = object
|
||||
|
||||
proc `=`(lhs: var T, rhs: T) =
|
||||
echo "assign"
|
||||
|
||||
proc `=destroy`(v: var T) =
|
||||
echo "destroy"
|
||||
|
||||
block:
|
||||
var v1 : T
|
||||
var v2 : T = v1
|
||||
|
||||
|
||||
# bug #1632
|
||||
|
||||
type
|
||||
Foo = object of RootObj
|
||||
x: int
|
||||
|
||||
proc `=destroy`(a: var Foo) =
|
||||
echo "destroy Foo: " & $a.x
|
||||
|
||||
template toFooPtr(a: int{lit}): ptr Foo =
|
||||
var temp = Foo(x:a)
|
||||
temp.addr
|
||||
|
||||
proc test(a: ptr Foo) =
|
||||
echo a[].x
|
||||
|
||||
proc main =
|
||||
test(toFooPtr(5))
|
||||
test(toFooPtr(123))
|
||||
|
||||
main()
|
||||
@@ -1,6 +1,11 @@
|
||||
discard """
|
||||
output: '''hi
|
||||
hi'''
|
||||
hi
|
||||
1
|
||||
hi
|
||||
2
|
||||
B
|
||||
A'''
|
||||
"""
|
||||
|
||||
# bug #1742
|
||||
@@ -16,3 +21,23 @@ import strutils
|
||||
let x = try: parseInt("133a")
|
||||
except: -1
|
||||
finally: echo "hi"
|
||||
|
||||
|
||||
template atFuncEnd =
|
||||
defer:
|
||||
echo "A"
|
||||
defer:
|
||||
echo "B"
|
||||
|
||||
template testB(): expr =
|
||||
let a = 0
|
||||
defer: echo "hi" # Delete this line to make it work
|
||||
a
|
||||
|
||||
proc main =
|
||||
atFuncEnd()
|
||||
echo 1
|
||||
let i = testB()
|
||||
echo 2
|
||||
|
||||
main()
|
||||
|
||||
10
tests/generics/mclosed_sym.nim
Normal file
10
tests/generics/mclosed_sym.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
type R* = object
|
||||
|
||||
type Data*[T] = object
|
||||
d*: T
|
||||
|
||||
proc same(r:R, d:int) = echo "TEST2"
|
||||
|
||||
proc doIt*(d:Data, r:R) =
|
||||
r.same(1) # Expecting this to invoke the local `same()` method
|
||||
11
tests/generics/tclosed_sym.nim
Normal file
11
tests/generics/tclosed_sym.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
discard """
|
||||
output: "TEST2"
|
||||
"""
|
||||
|
||||
# bug #2664
|
||||
|
||||
import mclosed_sym
|
||||
|
||||
proc same(r:R, d:int) = echo "TEST1"
|
||||
|
||||
doIt(Data[int](d:123), R())
|
||||
@@ -21,6 +21,11 @@ test "unittest typedescs":
|
||||
check(none(int) != some(1))
|
||||
|
||||
|
||||
test "unittest multiple requires":
|
||||
require(true)
|
||||
require(true)
|
||||
|
||||
|
||||
import math
|
||||
from strutils import parseInt
|
||||
proc defectiveRobot() =
|
||||
|
||||
13
tests/template/twhen_gensym.nim
Normal file
13
tests/template/twhen_gensym.nim
Normal file
@@ -0,0 +1,13 @@
|
||||
discard """
|
||||
output: "hi"
|
||||
"""
|
||||
|
||||
# bug #2670
|
||||
template testTemplate(b: bool): stmt =
|
||||
when b:
|
||||
var a = "hi"
|
||||
else:
|
||||
var a = 5
|
||||
echo a
|
||||
|
||||
testTemplate(true)
|
||||
Reference in New Issue
Block a user