Skip to content

Commit 61e98e9

Browse files
ringaboutnarimiran
authored andcommitted
fixes #25252; Unexpected ambiguous call with fields over object with default fields (#25256)
fixes #25252 (cherry picked from commit d54b5f3)
1 parent 7f6c0af commit 61e98e9

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

compiler/semtypes.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
533533
typ = a[^1].typ
534534
else:
535535
fitDefaultNode(c, a[^1], typ)
536-
typ = a[^1].typ
536+
typ = a[^1].typ.skipIntLit(c.idgen)
537537
elif a[^2].kind != nkEmpty:
538538
typ = semTypeNode(c, a[^2], nil)
539539
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,
905905
typ = n[^1].typ
906906
else:
907907
fitDefaultNode(c, n[^1], typ)
908-
typ = n[^1].typ
908+
typ = n[^1].typ.skipIntLit(c.idgen)
909909
propagateToOwner(rectype, typ)
910910
elif n[^2].kind == nkEmpty:
911911
localError(c.config, n.info, errTypeExpected)

compiler/semtypinst.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0; expectedType: PT
280280
(cl.owner == nil or result.sym.owner == cl.owner):
281281
# instantiate default value of object/tuple field
282282
cl.c.fitDefaultNode(cl.c, result.sym.ast, result.sym.typ)
283-
result.sym.typ = result.sym.ast.typ
283+
result.sym.typ = result.sym.ast.typ.skipIntLit(cl.c.idgen)
284284
# sym type can be nil if was gensym created by macro, see #24048
285285
if result.sym.typ != nil and result.sym.typ.kind == tyVoid:
286286
# don't add the 'void' field

tests/objects/tobject_default_value.nim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ template main {.dirty.} =
375375
type
376376
Color = enum
377377
Red, Blue, Yellow
378-
378+
379379
type
380380
ObjectVarint3 = object
381381
case kind: Color = Blue
@@ -663,7 +663,7 @@ template main {.dirty.} =
663663

664664
when not(T is void):
665665
v.vResultPrivate
666-
666+
667667
type R = Result[int, string]
668668

669669
proc testAssignResult() =
@@ -811,3 +811,17 @@ template main {.dirty.} =
811811

812812
static: main()
813813
main()
814+
815+
type
816+
Thing = object
817+
a: int = 100 # this is fine
818+
b = 100 # this is not
819+
820+
proc overloaded[T: SomeSignedInt](x: T) = discard
821+
proc overloaded[T: SomeUnsignedInt](x: T) = discard
822+
proc overloaded[T: object](x: T) =
823+
for val in fields(x):
824+
var v: typeof(val)
825+
overloaded(v)
826+
827+
overloaded(Thing())

0 commit comments

Comments
 (0)