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

@@ -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