fixes #21801; object field initialization with overloaded functions (#21805)

* fixes #21801; object field initialization with overloaded functions

* use the correct type
This commit is contained in:
ringabout
2023-05-08 19:52:28 +08:00
committed by GitHub
parent 71f2e1a502
commit ebdff1c7d3
2 changed files with 24 additions and 1 deletions

View File

@@ -227,8 +227,8 @@ proc isRecursiveType(t: PType, cycleDetector: var IntSet): bool =
proc fitDefaultNode(c: PContext, n: PNode): PType =
let expectedType = if n[^2].kind != nkEmpty: semTypeNode(c, n[^2], nil) else: nil
let oldType = n[^1].typ
n[^1] = semConstExpr(c, n[^1], expectedType = expectedType)
let oldType = n[^1].typ
n[^1].flags.incl nfSem
if n[^2].kind != nkEmpty:
if expectedType != nil and oldType != expectedType:

View File

@@ -591,6 +591,29 @@ template main {.dirty.} =
mainSync()
block: # bug #21801
func evaluate(i: int): float =
0.0
func evaluate(): float =
0.0
type SearchOptions = object
evaluation: proc(): float = evaluate
block:
func evaluate(): float =
0.0
type SearchOptions = object
evaluation: proc(): float = evaluate
block:
func evaluate(i: int): float =
0.0
type SearchOptions = object
evaluation = evaluate
static: main()
main()