fixes #23545; C compiler error when default initializing an object field function (#24375)

fixes #23545

(cherry picked from commit 815bbf0e73)
This commit is contained in:
ringabout
2024-10-29 15:08:35 +08:00
committed by narimiran
parent 022bd12e82
commit babc7d8c16
2 changed files with 30 additions and 0 deletions

View File

@@ -257,6 +257,22 @@ proc isRecursiveType(t: PType, cycleDetector: var IntSet): bool =
else:
return false
proc annotateClosureConv(n: PNode) =
case n.kind
of {nkNone..nkNilLit}:
discard
of nkTupleConstr:
if n.typ.kind == tyProc and n.typ.callConv == ccClosure and
n[0].typ.kind == tyProc and n[0].typ.callConv != ccClosure:
# restores `transf.generateThunk`
n[0] = newTreeIT(nkHiddenSubConv, n[0].info, n.typ,
newNodeI(nkEmpty, n[0].info), n[0])
n.transitionSonsKind(nkClosure)
n.flags.incl nfTransf
else:
for i in 0..<n.len:
annotateClosureConv(n[i])
proc fitDefaultNode(c: PContext, n: PNode): PType =
inc c.inStaticContext
let expectedType = if n[^2].kind != nkEmpty: semTypeNode(c, n[^2], nil) else: nil
@@ -272,6 +288,7 @@ proc fitDefaultNode(c: PContext, n: PNode): PType =
# `changeType` to infer types for constant values
# that's also the reason why we don't use `semExpr` to check
# the type since two overlapping error messages might be produced
annotateClosureConv(n)
result = n[^1].typ
else:
result = n[^1].typ

View File

@@ -776,5 +776,18 @@ template main {.dirty.} =
var d: limited_int;
doAssert d == 1
block: # bug #23545
proc evaluate(params: int) =
discard
proc evaluate() =
discard
type SearchInfo = object
evaluation: proc() = evaluate
var a = SearchInfo()
a.evaluation()
static: main()
main()