add type check for default fields (#20652)
This commit is contained in:
parent
064b72a59c
commit
c1343739e1
2 changed files with 32 additions and 2 deletions
|
|
@ -485,7 +485,11 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
|
|||
var hasDefaultField = a[^1].kind != nkEmpty
|
||||
if hasDefaultField:
|
||||
a[^1] = semConstExpr(c, a[^1])
|
||||
typ = a[^1].typ
|
||||
if a[^2].kind != nkEmpty:
|
||||
typ = semTypeNode(c, a[^2], nil)
|
||||
typ = fitNodeConsiderViewType(c, typ, a[^1], a[^1].info).typ
|
||||
else:
|
||||
typ = a[^1].typ
|
||||
elif a[^2].kind != nkEmpty:
|
||||
typ = semTypeNode(c, a[^2], nil)
|
||||
if c.graph.config.isDefined("nimPreviewRangeDefault") and typ.skipTypes(abstractInst).kind == tyRange:
|
||||
|
|
@ -820,7 +824,11 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
|||
var hasDefaultField = n[^1].kind != nkEmpty
|
||||
if hasDefaultField:
|
||||
n[^1] = semConstExpr(c, n[^1])
|
||||
typ = n[^1].typ
|
||||
if n[^2].kind != nkEmpty:
|
||||
typ = semTypeNode(c, n[^2], nil)
|
||||
typ = fitNodeConsiderViewType(c, typ, n[^1], n[^1].info).typ
|
||||
else:
|
||||
typ = n[^1].typ
|
||||
propagateToOwner(rectype, typ)
|
||||
elif n[^2].kind == nkEmpty:
|
||||
localError(c.config, n.info, errTypeExpected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue