fixes #25252; Unexpected ambiguous call with fields over object with default fields (#25256)

fixes #25252

(cherry picked from commit d54b5f3ae1)
This commit is contained in:
ringabout
2025-11-04 20:08:07 +08:00
committed by narimiran
parent 7f6c0afa59
commit 61e98e9bf1
3 changed files with 19 additions and 5 deletions

View File

@@ -533,7 +533,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
typ = a[^1].typ
else:
fitDefaultNode(c, a[^1], typ)
typ = a[^1].typ
typ = a[^1].typ.skipIntLit(c.idgen)
elif a[^2].kind != nkEmpty:
typ = semTypeNode(c, a[^2], nil)
if c.graph.config.isDefined("nimPreviewRangeDefault") and typ.skipTypes(abstractInst).kind == tyRange:
@@ -905,7 +905,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
typ = n[^1].typ
else:
fitDefaultNode(c, n[^1], typ)
typ = n[^1].typ
typ = n[^1].typ.skipIntLit(c.idgen)
propagateToOwner(rectype, typ)
elif n[^2].kind == nkEmpty:
localError(c.config, n.info, errTypeExpected)

View File

@@ -280,7 +280,7 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0; expectedType: PT
(cl.owner == nil or result.sym.owner == cl.owner):
# instantiate default value of object/tuple field
cl.c.fitDefaultNode(cl.c, result.sym.ast, result.sym.typ)
result.sym.typ = result.sym.ast.typ
result.sym.typ = result.sym.ast.typ.skipIntLit(cl.c.idgen)
# sym type can be nil if was gensym created by macro, see #24048
if result.sym.typ != nil and result.sym.typ.kind == tyVoid:
# don't add the 'void' field

View File

@@ -375,7 +375,7 @@ template main {.dirty.} =
type
Color = enum
Red, Blue, Yellow
type
ObjectVarint3 = object
case kind: Color = Blue
@@ -663,7 +663,7 @@ template main {.dirty.} =
when not(T is void):
v.vResultPrivate
type R = Result[int, string]
proc testAssignResult() =
@@ -811,3 +811,17 @@ template main {.dirty.} =
static: main()
main()
type
Thing = object
a: int = 100 # this is fine
b = 100 # this is not
proc overloaded[T: SomeSignedInt](x: T) = discard
proc overloaded[T: SomeUnsignedInt](x: T) = discard
proc overloaded[T: object](x: T) =
for val in fields(x):
var v: typeof(val)
overloaded(v)
overloaded(Thing())