diff options
Diffstat (limited to 'tests/objects')
-rw-r--r-- | tests/objects/tillegal_recursion.nim | 7 | ||||
-rw-r--r-- | tests/objects/tobjcov.nim | 4 | ||||
-rw-r--r-- | tests/objects/tobject.nim | 2 | ||||
-rw-r--r-- | tests/objects/tobject2.nim | 2 | ||||
-rw-r--r-- | tests/objects/tobject3.nim | 2 | ||||
-rw-r--r-- | tests/objects/tobjects.nim | 2 | ||||
-rw-r--r-- | tests/objects/tobjloop.nim | 15 | ||||
-rw-r--r-- | tests/objects/tobjpragma.nim | 10 | ||||
-rw-r--r-- | tests/objects/tofopr.nim | 8 | ||||
-rw-r--r-- | tests/objects/toop.nim | 6 | ||||
-rw-r--r-- | tests/objects/toop1.nim | 24 | ||||
-rw-r--r-- | tests/objects/trefobjsyntax2.nim | 19 | ||||
-rw-r--r-- | tests/objects/trefobjsyntax3.nim | 28 |
13 files changed, 99 insertions, 30 deletions
diff --git a/tests/objects/tillegal_recursion.nim b/tests/objects/tillegal_recursion.nim new file mode 100644 index 000000000..222139101 --- /dev/null +++ b/tests/objects/tillegal_recursion.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "inheritance only works with non-final objects" + line: 7 +""" +# bug #1691 +type + Foo = ref object of Foo diff --git a/tests/objects/tobjcov.nim b/tests/objects/tobjcov.nim index 8391727f2..cf2e5becf 100644 --- a/tests/objects/tobjcov.nim +++ b/tests/objects/tobjcov.nim @@ -5,10 +5,10 @@ type a: int TB = object of TA b: array[0..5000_000, int] - + proc ap(x: var TA) = x.a = -1 proc bp(x: var TB) = x.b[high(x.b)] = -1 - + # in Nim proc (x: TB) is compatible to proc (x: TA), # but this is not type safe: var f = cast[proc (x: var TA) {.nimcall.}](bp) diff --git a/tests/objects/tobject.nim b/tests/objects/tobject.nim index 5fec84441..cdb8f80db 100644 --- a/tests/objects/tobject.nim +++ b/tests/objects/tobject.nim @@ -3,7 +3,7 @@ import unittest type Obj = object foo: int -proc makeObj(x: int): Obj = +proc makeObj(x: int): Obj = result.foo = x suite "object basic methods": diff --git a/tests/objects/tobject2.nim b/tests/objects/tobject2.nim index 0f1869695..a49296843 100644 --- a/tests/objects/tobject2.nim +++ b/tests/objects/tobject2.nim @@ -9,7 +9,7 @@ type proc getPoint( p: var TPoint2d) = {.breakpoint.} - writeln(stdout, p.x) + writeLine(stdout, p.x) var p: TPoint3d diff --git a/tests/objects/tobject3.nim b/tests/objects/tobject3.nim index 85cf1cfe3..2d9c8d023 100644 --- a/tests/objects/tobject3.nim +++ b/tests/objects/tobject3.nim @@ -4,7 +4,7 @@ type TFoo = ref object of RootObj - Data: int + Data: int TBar = ref object of TFoo nil TBar2 = ref object of TBar diff --git a/tests/objects/tobjects.nim b/tests/objects/tobjects.nim index 06fa15583..2f46b46b5 100644 --- a/tests/objects/tobjects.nim +++ b/tests/objects/tobjects.nim @@ -18,7 +18,7 @@ type of 0: arg: char of 1: s: string else: wtf: bool - + var x: TMyObject diff --git a/tests/objects/tobjloop.nim b/tests/objects/tobjloop.nim new file mode 100644 index 000000000..9fea1e2fb --- /dev/null +++ b/tests/objects/tobjloop.nim @@ -0,0 +1,15 @@ +discard """ + output: "is Nil false" +""" +# bug #1658 + +type + Loop* = ref object + onBeforeSelect*: proc (L: Loop) + +var L: Loop +new L +L.onBeforeSelect = proc (bar: Loop) = + echo "is Nil ", bar.isNil + +L.onBeforeSelect(L) diff --git a/tests/objects/tobjpragma.nim b/tests/objects/tobjpragma.nim index dda8057b6..0a6cc893b 100644 --- a/tests/objects/tobjpragma.nim +++ b/tests/objects/tobjpragma.nim @@ -12,7 +12,7 @@ discard """ # Disabled since some versions of GCC ignore the 'packed' attribute -# Test +# Test type Foo {.packed.} = object @@ -21,12 +21,12 @@ type Bar {.packed.} = object a: int8 - b: int16 - + b: int16 + Daz {.packed.} = object a: int32 - b: int8 - c: int32 + b: int8 + c: int32 var f = Foo(a: 1, b: 1) diff --git a/tests/objects/tofopr.nim b/tests/objects/tofopr.nim index 961d81bd3..ab2854571 100644 --- a/tests/objects/tofopr.nim +++ b/tests/objects/tofopr.nim @@ -8,12 +8,12 @@ type TMyType = object {.inheritable.} len: int data: string - + TOtherType = object of TMyType - -proc p(x: TMyType): bool = + +proc p(x: TMyType): bool = return x of TOtherType - + var m: TMyType n: TOtherType diff --git a/tests/objects/toop.nim b/tests/objects/toop.nim index 0b42c2c22..ebc59f637 100644 --- a/tests/objects/toop.nim +++ b/tests/objects/toop.nim @@ -5,13 +5,13 @@ discard """ type TA = object of TObject x, y: int - + TB = object of TA z: int - + TC = object of TB whatever: string - + proc p(a: var TA) = echo "a" proc p(b: var TB) = echo "b" diff --git a/tests/objects/toop1.nim b/tests/objects/toop1.nim index 0d8ba124b..4727d146d 100644 --- a/tests/objects/toop1.nim +++ b/tests/objects/toop1.nim @@ -8,17 +8,17 @@ import macros type TFigure = object of RootObj # abstract base class: draw: proc (my: var TFigure) {.nimcall.} # concrete classes implement this - -proc init(f: var TFigure) = + +proc init(f: var TFigure) = f.draw = nil type TCircle = object of TFigure radius: int - -proc drawCircle(my: var TCircle) = stdout.writeln("o " & $my.radius) -proc init(my: var TCircle) = +proc drawCircle(my: var TCircle) = stdout.writeLine("o " & $my.radius) + +proc init(my: var TCircle) = init(TFigure(my)) # call base constructor my.radius = 5 my.draw = cast[proc (my: var TFigure) {.nimcall.}](drawCircle) @@ -29,13 +29,13 @@ type proc drawRectangle(my: var TRectangle) = stdout.write("[]") -proc init(my: var TRectangle) = +proc init(my: var TRectangle) = init(TFigure(my)) # call base constructor my.width = 5 my.height = 10 my.draw = cast[proc (my: var TFigure) {.nimcall.}](drawRectangle) -macro `!` (n: expr): stmt {.immediate.} = +macro `!` (n: expr): stmt {.immediate.} = let n = callsite() result = newNimNode(nnkCall, n) var dot = newNimNode(nnkDotExpr, n) @@ -60,16 +60,16 @@ type FHost: int # cannot be accessed from the outside of the module # the `F` prefix is a convention to avoid clashes since # the accessors are named `host` - -proc `host=`*(s: var TSocket, value: int) {.inline.} = + +proc `host=`*(s: var TSocket, value: int) {.inline.} = ## setter of hostAddr s.FHost = value proc host*(s: TSocket): int {.inline.} = ## getter of hostAddr return s.FHost - -var + +var s: TSocket s.host = 34 # same as `host=`(s, 34) stdout.write(s.host) @@ -81,6 +81,6 @@ var init(r) init(c) r!draw -c!draw() +c!draw() #OUT 34[]o 5 diff --git a/tests/objects/trefobjsyntax2.nim b/tests/objects/trefobjsyntax2.nim new file mode 100644 index 000000000..8ee209cc7 --- /dev/null +++ b/tests/objects/trefobjsyntax2.nim @@ -0,0 +1,19 @@ +# bug #2508 + +type + GenericNodeObj[T] = ref object + obj: T + + Node* = ref object + children*: seq[Node] + parent*: Node + + nodeObj*: GenericNodeObj[int] + +proc newNode*(nodeObj: GenericNodeObj): Node = + result = Node(nodeObj: nodeObj) + newSeq(result.children, 10) + +var genericObj = GenericNodeObj[int]() + +var myNode = newNode(genericObj) diff --git a/tests/objects/trefobjsyntax3.nim b/tests/objects/trefobjsyntax3.nim new file mode 100644 index 000000000..2d466eeda --- /dev/null +++ b/tests/objects/trefobjsyntax3.nim @@ -0,0 +1,28 @@ +# bug #2540 + +type + BaseSceneNode[T] = ref object of RootObj + children*: seq[BaseSceneNode[T]] + parent*: BaseSceneNode[T] + + SceneNode[T] = ref object of BaseSceneNode[T] + + SomeObj = ref object + +proc newSceneNode[T](): SceneNode[T] = + new result + result.children = @[] + +var aNode = newSceneNode[SomeObj]() + + +# bug #3038 + +type + Data[T] = ref object of RootObj + data: T + Type = ref object of RootObj + SubType[T] = ref object of Type + data: Data[T] + SubSubType = ref object of SubType + SubSubSubType = ref object of SubSubType |