const view types; fixes some cases from https://github.com/nim-lang/Nim/issues/15428 (#15488)

This commit is contained in:
Andreas Rumpf 2020-10-05 18:31:46 +02:00 • committed by GitHub
commit 4e438f9096
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 47 deletions

View file

@ -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