From 96513b2506d9057744da9926986181294a3da653 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:36:20 +0800 Subject: fixes #22926; Different type inferred when setting a default value for an array field (#22999) fixes #22926 --- tests/objects/tobject_default_value.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/objects/tobject_default_value.nim') diff --git a/tests/objects/tobject_default_value.nim b/tests/objects/tobject_default_value.nim index 3af790da6..152b355f4 100644 --- a/tests/objects/tobject_default_value.nim +++ b/tests/objects/tobject_default_value.nim @@ -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() -- cgit 1.4.1-2-gfad0