summary refs log tree commit diff stats
path: root/tests/views
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-10-05 18:31:46 +0200
committerGitHub <noreply@github.com>2020-10-05 18:31:46 +0200
commit4e438f9096fc413824bdbe8377a4ca376d63be35 (patch)
tree3f3dd5907e3b8469423da747418e3d7abbdd4d81 /tests/views
parent1e28cea0d102afd43a62f6f7fcabd65cd8996762 (diff)
downloadNim-4e438f9096fc413824bdbe8377a4ca376d63be35.tar.gz
const view types; fixes some cases from https://github.com/nim-lang/Nim/issues/15428 (#15488)
Diffstat (limited to 'tests/views')
-rw-r--r--tests/views/tconst_views.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/views/tconst_views.nim b/tests/views/tconst_views.nim
new file mode 100644
index 000000000..d7f1fc481
--- /dev/null
+++ b/tests/views/tconst_views.nim
@@ -0,0 +1,26 @@
+discard """
+  cmd: "nim c --experimental:views $file"
+  output: '''(data: [1, 2, 3], other: 4)
+[1, 20, 3]'''
+"""
+
+type
+  Foo = object
+    data: openArray[int]
+    other: int
+
+const
+  c = Foo(data: [1, 2, 3], other: 4)
+
+  c2 = Foo(data: [1, 20, 3], other: 4)
+
+proc `$`(x: openArray[int]): string =
+  result = "["
+  for i in x:
+    if result.len > 1: result.add ", "
+    result.add $i
+  result.add "]"
+
+echo c
+echo c2.data
+