Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,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:
Expand Down Expand Up @@ -928,7 +928,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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/objects/tobject_default_value.nim
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,18 @@ block:

var t = MyTyp()
t.thing[""] = ""


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())
Loading