fixes #22926; Different type inferred when setting a default value for an array field (#22999)

fixes #22926
This commit is contained in:
ringabout
2023-11-29 17:36:20 +08:00
committed by GitHub
parent 795aad4f2a
commit 96513b2506
3 changed files with 36 additions and 6 deletions

View File

@@ -717,6 +717,33 @@ template main {.dirty.} =
doAssert T().kind == B
block: # bug #22926
type
Direction = enum
North
South
East
West
ArrayObj1 = object
list: array[Direction, int]
ArrayObj2 = object
list: array[Direction, int] = [1, 2, 3, 4]
block:
var a: ArrayObj1
doAssert a.list[West] == 0
var b = default ArrayObj1
doAssert b.list[North] == 0
block:
var a: ArrayObj2
doAssert a.list[West] == 0
var b = default ArrayObj2
doAssert b.list[North] == 1
static: main()
main()