diff options
Diffstat (limited to 'tests/constructors')
-rw-r--r-- | tests/constructors/a.nim | 2 | ||||
-rw-r--r-- | tests/constructors/b.nim | 2 | ||||
-rw-r--r-- | tests/constructors/t18990.nim | 3 | ||||
-rw-r--r-- | tests/constructors/tconstr1.nim | 28 | ||||
-rw-r--r-- | tests/constructors/tconstr2.nim | 22 |
5 files changed, 57 insertions, 0 deletions
diff --git a/tests/constructors/a.nim b/tests/constructors/a.nim new file mode 100644 index 000000000..03788fc57 --- /dev/null +++ b/tests/constructors/a.nim @@ -0,0 +1,2 @@ +type A* = object + a: uint8 \ No newline at end of file diff --git a/tests/constructors/b.nim b/tests/constructors/b.nim new file mode 100644 index 000000000..437dd0550 --- /dev/null +++ b/tests/constructors/b.nim @@ -0,0 +1,2 @@ +type B* = object +proc A*(a, b: float): B = discard \ No newline at end of file diff --git a/tests/constructors/t18990.nim b/tests/constructors/t18990.nim new file mode 100644 index 000000000..2f60f3c2c --- /dev/null +++ b/tests/constructors/t18990.nim @@ -0,0 +1,3 @@ +import a, b +discard A(1f, 1f) # works +proc x(b = A(1f, 1f)) = discard # doesn't work \ No newline at end of file diff --git a/tests/constructors/tconstr1.nim b/tests/constructors/tconstr1.nim new file mode 100644 index 000000000..a169bf453 --- /dev/null +++ b/tests/constructors/tconstr1.nim @@ -0,0 +1,28 @@ +discard """ + errormsg: "type mismatch" + file: "tconstr1.nim" + line: 25 +""" +# Test array, record constructors + +type + TComplexRecord = tuple[ + s: string, + x, y: int, + z: float, + chars: set[char]] + +proc testSem = + var + things: array[0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})] + write(stdout, things[0].x) + +const + things: array[0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR + otherThings = [ # the same + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] diff --git a/tests/constructors/tconstr2.nim b/tests/constructors/tconstr2.nim new file mode 100644 index 000000000..2557d7db9 --- /dev/null +++ b/tests/constructors/tconstr2.nim @@ -0,0 +1,22 @@ +discard """ + output: "69" +""" +# Test array, record constructors + +type + TComplexRecord = tuple[ + s: string, + x, y: int, + z: float, + chars: set[char]] + +const + things: array[0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {})] + otherThings = [ # the same + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] + +writeLine(stdout, things[0].x) +#OUT 69 |