-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Different type inferred when setting a default value for an array field #22926
Comments
Just for a workaround: type
Direction = enum
North
South
East
West
ArrayObj1 = object
list: array[Direction, int]
ArrayObj2 = object
list: array[Direction, int] = [North: 1, 2, 3, 4]
var a: ArrayObj1
for i in Direction:
echo a.list[i]
var b: ArrayObj2
for i in Direction:
echo b.list[i] |
Thanks for the workaround, @beef331. I'll use that for the time being. |
Araq
pushed a commit
that referenced
this issue
Nov 29, 2023
narimiran
pushed a commit
that referenced
this issue
Apr 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When setting a default value for an array field in an object where the size is as an enumeration type, attempting to iterate over the array in a for-loop yields a compiler error because it infers the type as being different than the declared type.
The code below illustrates the issue:
Nim Version
Nim Compiler Version 2.0.0 [MacOSX: amd64]
Compiled at 2023-10-05
Copyright (c) 2006-2023 by Andreas Rumpf
active boot switches: -d:release
Current Output
Expected Output
The program to compile without error.
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: