Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen error when object constructor is used for result containing view type #15746

Closed
jrfondren opened this issue Oct 27, 2020 · 0 comments · Fixed by #23608
Closed

Codegen error when object constructor is used for result containing view type #15746

jrfondren opened this issue Oct 27, 2020 · 0 comments · Fixed by #23608

Comments

@jrfondren
Copy link
Contributor

Example

{.experimental: "views".}

type
  Reader = object
    data: openArray[char]
    current: int

proc initReader(data: openArray[char], offset = 0): Reader =
  when defined(bad):
    result = Reader(data: data, current: offset)
  when defined(good):
    result.data = data
    result.current = offset

let s = "\x01\x00\x00\x00"
echo initReader(s).data[0].int

Current Output -d:good

1

Current Output -d:bad

....CC: bug2.nim
/home/jfondren/.cache/nim/bug2_d/@mbug2.nim.c: In function ‘initReader__UYdi27TUMFesBFKaWXlJFQ’:
/home/jfondren/.cache/nim/bug2_d/@mbug2.nim.c:346:16: error: incompatible types when assigning to type ‘tyOpenArray__g7UvpSI7wiag75QHJKQ1sQ’ from type ‘NIM_CHAR *’ {aka ‘char *’}
  346 |  result.data = data;
      |                ^~~~

Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/jfondren/.choosenim/toolchains/nim-1.4.0/lib -I/home/jfondren/nim/bugs -o /home/jfondren/.cache/nim/bug2_d/@mbug2.nim.c.o /home/jfondren/.cache/nim/bug2_d/@mbug2.nim.c' failed with exit code: 1

Additional Information

$ nim -v
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants