summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-11-29 17:36:20 +0800
committerGitHub <noreply@github.com>2023-11-29 10:36:20 +0100
commit96513b2506d9057744da9926986181294a3da653 (patch)
treee517c18a371a395aa03887a52d035dd3187f6c87 /compiler
parent795aad4f2a0032ed9b54a7b89dc08b420981e208 (diff)
downloadNim-96513b2506d9057744da9926986181294a3da653.tar.gz
fixes #22926; Different type inferred when setting a default value for an array field (#22999)
fixes #22926
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semtypes.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index a2e7bb639..e234c6b1f 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -245,6 +245,12 @@ proc fitDefaultNode(c: PContext, n: PNode): PType =
   if n[^2].kind != nkEmpty:
     if expectedType != nil and oldType != expectedType:
       n[^1] = fitNodeConsiderViewType(c, expectedType, n[^1], n[^1].info)
+      changeType(c, n[^1], expectedType, true) # infer types for default fields value
+        # bug #22926; be cautious that it uses `semConstExpr` to
+        # evaulate the default fields; it's only natural to use
+        # `changeType` to infer types for constant values
+        # that's also the reason why we don't use `semExpr` to check
+        # the type since two overlapping error messages might be produced
     result = n[^1].typ
   else:
     result = n[^1].typ