Skip to content

Viewtype codegen error turns a single proc call into two #15778

@jrfondren

Description

@jrfondren

Example

{.experimental: "views".} type Reader = object data: openArray[char] current: int proc read(data: var Reader, length: int): openArray[char] = echo "asked to read ", length, " at ", data.current let start = data.current data.current.inc length return data.data.toOpenArray(start, data.current-1) var data = "hello there" var reader = Reader(data: data.toOpenArray(0, data.len-1), current: 0) echo reader.read(2) echo reader.read(3)

Current Output

asked to read 2 at 0 asked to read 2 at 2 ['h', 'e'] asked to read 3 at 4 asked to read 3 at 7 ['o', ' ', 't'] 

Expected Output

asked to read 2 at 0 ['h', 'e'] asked to read 3 at 2 ['l', 'l', 'o'] 

Codegen

 T3_.Field0 = read__OKs9amEjlLUMn2SZAbNLz5g((&reader__zXiKN6CZe4nMuBYExP7Hvw), ((NI) 2)).Field0; T3_.Field1 = read__OKs9amEjlLUMn2SZAbNLz5g((&reader__zXiKN6CZe4nMuBYExP7Hvw), ((NI) 2)).Field1; 

The read function is called twice to copy both fields from the openArray.

Additional Information

Nim Compiler Version 1.4.0 [Linux: amd64] Compiled at 2020-10-16 Copyright (c) 2006-2020 by Andreas Rumpf git hash: bdcd87afca238a0a7b2c70971827cf9172817b12 active boot switches: -d:release 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions