diff options
-rw-r--r-- | compiler/semcall.nim | 2 | ||||
-rw-r--r-- | compiler/types.nim | 3 | ||||
-rw-r--r-- | tests/distinct/typeclassborrow.nim | 8 |
3 files changed, 11 insertions, 2 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index a4114497f..2c1939c3c 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -827,7 +827,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 diff --git a/compiler/types.nim b/compiler/types.nim index 31563b71f..46433a230 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -972,6 +972,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] @@ -1306,7 +1307,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: diff --git a/tests/distinct/typeclassborrow.nim b/tests/distinct/typeclassborrow.nim index ee0b07829..5e0c63953 100644 --- a/tests/distinct/typeclassborrow.nim +++ b/tests/distinct/typeclassborrow.nim @@ -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.} |