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

Views: GCC error when construct object with openArray from proc parameter #20048

Closed
gabbhack opened this issue Jul 17, 2022 · 2 comments · Fixed by #23608
Closed

Views: GCC error when construct object with openArray from proc parameter #20048

gabbhack opened this issue Jul 17, 2022 · 2 comments · Fixed by #23608
Assignees

Comments

@gabbhack
Copy link

Example

{.experimental: "views".}

type
  Test = object
    tokens: openArray[string]

func init(Self: typedesc[Test], tokens: openArray[string]): Self = Self(tokens: tokens)

echo Test.init ["123"]

https://play.nim-lang.org/#ix=44yx

Current Output

C:\Users\Noname\nimcache\a_d\@ma.nim.c: In function 'init__a_9':
C:\Users\Noname\nimcache\a_d\@ma.nim.c:111:25: error: incompatible types when assigning to type 'tyOpenArray__eiGhHdDILTzcMBo9aGYM3ww' from type 'NimStringDesc **'
  111 |         result.tokens = tokens;
      |                         ^~~~~~
Error: execution of an external compiler program 'gcc.exe -c  -w -fmax-errors=3 -mno-ms-bitfields   -IC:\Users\Noname\.choosenim\toolchains\nim-1.6.6\lib -IC:\Users\Noname\Desktop -o C:\Users\Noname\nimcache\a_d\@ma.nim.c.o C:\Users\Noname\nimcache\a_d\@ma.nim.c' failed with exit code: 1

Expected Output

(tokens: ["123"])

Workaround

{.experimental: "views".}

type
  Test = object
    tokens: openArray[string]

func init(Self: typedesc[Test], tokens: openArray[string]): Self = 
  Self(tokens: tokens.toOpenArray(tokens.low, tokens.high))

echo Test.init ["123"]
$ nim -v
Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release
@gabbhack
Copy link
Author

I guess related:

{.experimental: "views".}

type
  Test = object
    tokens: openArray[int]

func init(Self: typedesc[Test], tokens: openArray[int]): Self = 
  Self(tokens: tokens.toOpenArray(tokens.low, tokens.high))

func main() =
  var test = Test.init [1,2,3]
  test.tokens = test.tokens[1..test.tokens.high]

main()

https://play.nim-lang.org/#ix=44Ae

Output:

/usercode/nimcache/@min.nim.c: In function 'main__in_9':
/usercode/nimcache/@min.nim.c:177:82: error: 'X5BX5D___in_80(test.tokens.Field0,  test.tokens.Field1,  T1_)' is a pointer; did you mean to use '->'?
  test.tokens.Field0 = X5BX5D___in_80(test.tokens.Field0, test.tokens.Field1, T1_).Field0; test.tokens.Field1 = X5BX5D___in_80(test.tokens.Field0, test.tokens.Field1, T1_).Field1;
                                                                                  ^
                                                                                  ->
/usercode/nimcache/@min.nim.c:177:171: error: 'X5BX5D___in_80(test.tokens.Field0,  test.tokens.Field1,  T1_)' is a pointer; did you mean to use '->'?
  test.tokens.Field0 = X5BX5D___in_80(test.tokens.Field0, test.tokens.Field1, T1_).Field0; test.tokens.Field1 = X5BX5D___in_80(test.tokens.Field0, test.tokens.Field1, T1_).Field1;

@hamidb80
Copy link
Contributor

hamidb80 commented Aug 14, 2022

minimal example

proc test(a: openArray[int]) =
  echo (a, a.len)

test [1, 2, 3]

error:

 error: incompatible types when assigning to type 'tyOpenArray__0HB6wOMHiJYheBmdOv6sWw' {aka 'struct <anonymous>'} from type 'NI *' {aka 'long long int *'}
  T2_.Field0 = a;

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