fixes type check of ranges for default fields (#20660)
This commit is contained in:
parent
82b7423cea
commit
27896ed469
2 changed files with 15 additions and 2 deletions
|
|
@ -487,7 +487,8 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
|
||||||
a[^1] = semConstExpr(c, a[^1])
|
a[^1] = semConstExpr(c, a[^1])
|
||||||
if a[^2].kind != nkEmpty:
|
if a[^2].kind != nkEmpty:
|
||||||
typ = semTypeNode(c, a[^2], nil)
|
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:
|
else:
|
||||||
typ = a[^1].typ
|
typ = a[^1].typ
|
||||||
elif a[^2].kind != nkEmpty:
|
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])
|
n[^1] = semConstExpr(c, n[^1])
|
||||||
if n[^2].kind != nkEmpty:
|
if n[^2].kind != nkEmpty:
|
||||||
typ = semTypeNode(c, n[^2], nil)
|
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:
|
else:
|
||||||
typ = n[^1].typ
|
typ = n[^1].typ
|
||||||
propagateToOwner(rectype, typ)
|
propagateToOwner(rectype, typ)
|
||||||
|
|
|
||||||
11
tests/objects/tdefaultrangetypescheck.nim
Normal file
11
tests/objects/tdefaultrangetypescheck.nim
Normal 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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue