fixes #22902; borrow from proc return type mismatch (#22908)

fixes #22902

(cherry picked from commit 95e5ad6927)
This commit is contained in:
ringabout
2023-11-04 15:50:30 +08:00
committed by narimiran
parent bd829c093d
commit 3ae3050b80
3 changed files with 11 additions and 2 deletions

View File

@@ -809,7 +809,7 @@ proc searchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): tuple[s: PS
if resolved != nil:
result.s = resolved[0].sym
result.state = bsMatch
if not compareTypes(result.s.typ[0], fn.typ[0], dcEqIgnoreDistinct):
if not compareTypes(result.s.typ[0], fn.typ[0], dcEqIgnoreDistinct, {IgnoreFlags}):
result.state = bsReturnNotMatch
elif result.s.magic in {mArrPut, mArrGet}:
# cannot borrow these magics for now

View File

@@ -991,6 +991,7 @@ type
ExactGcSafety
AllowCommonBase
PickyCAliases # be picky about the distinction between 'cint' and 'int32'
IgnoreFlags # used for borrowed functions; ignores the tfVarIsPtr flag
TTypeCmpFlags* = set[TTypeCmpFlag]
@@ -1312,7 +1313,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
cycleCheck()
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
result = sameChildrenAux(a, b, c)
if result:
if result and IgnoreFlags notin c.flags:
if IgnoreTupleFields in c.flags:
result = a.flags * {tfVarIsPtr, tfIsOutParam} == b.flags * {tfVarIsPtr, tfIsOutParam}
else:

View File

@@ -1,3 +1,5 @@
import std/tables
type
Foo = distinct seq[int]
Bar[N: static[int]] = distinct seq[int]
@@ -46,3 +48,9 @@ proc `==`*(x, y: Fine): bool {.borrow.} =
var x = Fine("1234")
var y = Fine("1234")
doAssert x == y
block: # bug #22902
type
DistinctTable = distinct Table[int, int]
proc `[]`(t: DistinctTable; key: int): lent int {.borrow.}