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

Code gen error when repr'ing a type-casted UncheckedArray #18429

Open
dom96 opened this issue Jul 4, 2021 · 1 comment
Open

Code gen error when repr'ing a type-casted UncheckedArray #18429

dom96 opened this issue Jul 4, 2021 · 1 comment

Comments

@dom96
Copy link
Contributor

dom96 commented Jul 4, 2021

type
  Payload = object
    something: int
    vals: ptr UncheckedArray[int]
 
var x: Payload
var vals = [1,2,3]
x.vals = cast[ptr UncheckedArray[int]](addr vals)
x.vals[0] = 42
echo(x.vals[0])
echo(cast[array[5, byte]](x.vals[]).repr)

https://play.nim-lang.org/#ix=3rYy

Output:

/usercode/nimcache/@min.nim.c: In function 'NimMainModule':
/usercode/nimcache/@min.nim.c:208:14: error: assignment to expression with array type
  LOC3.source = x__EGWKGClUlppqAonIP2rgfg.vals;
@ringabout
Copy link
Member

Instead cast ptr array

type
  Payload = object
    something: int
    vals: ptr UncheckedArray[int]

var x: Payload
var vals = [1,2,3]
x.vals = cast[ptr UncheckedArray[int]](addr vals)
x.vals[0] = 42
echo(x.vals[0])
echo(cast[ptr array[5, byte]](x.vals)[].repr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants