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

Initialization of types with conditional fields (nkRecWhen) differs in const and non-const contexts #11226

Closed
linkmonitor opened this issue May 10, 2019 · 4 comments
Labels
VM see also `const` label

Comments

@linkmonitor
Copy link

linkmonitor commented May 10, 2019

I made a toy Point[] type, after seeing issue #7569, which is parameterized by a static[int] representing dimension.

The output from echoing instances of that type differs when the instance is const and non-const.

Example

type
  Point[T; dim:static[int]] = object
    when dim >= 1: x:T
    when dim >= 2: y:T
    when dim >= 3: z:T

proc main =
  let a = Point[int,2](x:1, y:2)
  echo a

  const b = Point[int,2](x:1, y:2)
  echo b

when isMainModule:
  main()

Current Output

(x: 1, y: 2)
(x: 2, y: 0)

Expected Output

(x: 1, y: 2)
(x: 1, y: 2)

Additional Information

Output of nim -v is

Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-10
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release

My Nim executable was built ~30 minutes before posting this issue, using choosenim update on the devel channel.

@mratsim mratsim added Static[T] VM see also `const` label and removed Static[T] labels May 10, 2019
@mratsim
Copy link
Collaborator

mratsim commented May 10, 2019

This is not static related, just the VM being buggy with initialization, especially conditionals, like #7569, #8015, #9622

type
  Point[T] = object
    when sizeof(T) >= 2: x:T
    when sizeof(T) >= 4: y:T
    when sizeof(T) >= 8: z:T

proc main =
  let a = Point[int32](x:1, y:2)
  echo a

  const b = Point[int32](x:1, y:2)
  echo b

when isMainModule:
  main()

@mratsim mratsim changed the title Initialization of types with static parameter differs in const and non-const contexts Initialization of types with conditional fields (nkRecWhen) differs in const and non-const contexts May 10, 2019
@krux02
Copy link
Contributor

krux02 commented May 10, 2019

I would like to point out that there is exists something like https://github.com/stavenko/nim-glm

@narimiran
Copy link
Member

I've run the original example with the latest Nim and it produces the expected result.

@linkmonitor can you confirm this is solved?

@linkmonitor
Copy link
Author

Works on my end; confirmed solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

No branches or pull requests

4 participants