Skip to content

Commit

Permalink
makes some exceptions for DateTime which contains a ref field
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Nov 28, 2023
1 parent 5e18761 commit abbdf9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ proc isRecursiveType(t: PType, cycleDetector: var IntSet): bool =
return false

proc fitDefaultNode(c: PContext, n: PNode): PType =
inc c.inStaticContext
let expectedType = if n[^2].kind != nkEmpty: semTypeNode(c, n[^2], nil) else: nil
n[^1] = semConstExpr(c, n[^1], expectedType = expectedType)
let oldType = n[^1].typ
Expand All @@ -249,7 +250,8 @@ proc fitDefaultNode(c: PContext, n: PNode): PType =
result = n[^1].typ
# xxx any troubles related to defaults fields, consult `semConst` for a potential answer
if n[^1].kind != nkNilLit:
typeAllowedCheck(c, n.info, result, skConst, {taProcContextIsNotMacro})
typeAllowedCheck(c, n.info, result, skConst, {taProcContextIsNotMacro, taIsDefaultField})
dec c.inStaticContext

proc isRecursiveType*(t: PType): bool =
# handle simple recusive types before typeFinalPass
Expand Down
5 changes: 3 additions & 2 deletions compiler/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type
taIsTemplateOrMacro
taProcContextIsNotMacro
taIsCastable
taIsDefaultField

TTypeAllowedFlags* = set[TTypeAllowedFlag]

Expand Down Expand Up @@ -172,7 +173,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
elif kind in {skVar, skLet}:
result = t[1]
of tyRef:
if kind == skConst: result = t
if kind == skConst and taIsDefaultField notin flags: result = t
else: result = typeAllowedAux(marker, t.lastSon, kind, c, flags+{taHeap})
of tyPtr:
result = typeAllowedAux(marker, t.lastSon, kind, c, flags+{taHeap})
Expand All @@ -182,7 +183,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
if result != nil: break
of tyObject, tyTuple:
if kind in {skProc, skFunc, skConst} and
t.kind == tyObject and t[0] != nil:
t.kind == tyObject and t[0] != nil and taIsDefaultField notin flags:
result = t
else:
let flags = flags+{taField}
Expand Down

0 comments on commit abbdf9f

Please sign in to comment.