fixes object default fields bugs and add tests (#20839)

* fixes object default fields bugs and add tests

* Update compiler/semmagic.nim

* Update compiler/sem.nim

* Update compiler/sem.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
ringabout 2022-11-15 00:31:06 +08:00 • committed by GitHub
commit 7f2ff909d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 20 deletions

View file

@ -326,7 +326,12 @@ proc semConstructFields(c: PContext, n: PNode, constrCtx: var ObjConstrContext,
result.status = initUnknown
result.defaults.add newTree(nkExprColonExpr, n, field.ast)
else:
result.status = initNone
let defaultExpr = defaultNodeField(c, n)
if defaultExpr != nil:
result.status = initUnknown
result.defaults.add newTree(nkExprColonExpr, n, defaultExpr)
else:
result.status = initNone
else:
internalAssert c.config, false