fixes type check of ranges for default fields (#20660)

This commit is contained in:
ringabout
2022-10-27 23:23:33 +08:00
committed by GitHub
parent 82b7423cea
commit 27896ed469
2 changed files with 15 additions and 2 deletions

View File

@@ -487,7 +487,8 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
a[^1] = semConstExpr(c, a[^1])
if a[^2].kind != nkEmpty:
typ = semTypeNode(c, a[^2], nil)
typ = fitNodeConsiderViewType(c, typ, a[^1], a[^1].info).typ
let def = semExprWithType(c, a[^1], {}, typ)
typ = fitNodeConsiderViewType(c, typ, def, def.info).typ
else:
typ = a[^1].typ
elif a[^2].kind != nkEmpty:
@@ -826,7 +827,8 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
n[^1] = semConstExpr(c, n[^1])
if n[^2].kind != nkEmpty:
typ = semTypeNode(c, n[^2], nil)
typ = fitNodeConsiderViewType(c, typ, n[^1], n[^1].info).typ
let def = semExprWithType(c, n[^1], {}, typ)
typ = fitNodeConsiderViewType(c, typ, def, def.info).typ
else:
typ = n[^1].typ
propagateToOwner(rectype, typ)

View File

@@ -0,0 +1,11 @@
discard """
errormsg: "conversion from int literal(0) to range 1..5(int) is invalid"
line: 9
"""
type
Point = object
y: int
x: range[1..5] = 0
echo default(Point)