fixes #516
This commit is contained in:
parent
b40ab4dc9e
commit
9c6de08db0
2 changed files with 23 additions and 3 deletions
|
|
@ -207,11 +207,14 @@ proc SearchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
|
||||||
# New approach: generate fn(x, y, z) where x, y, z have the proper types
|
# New approach: generate fn(x, y, z) where x, y, z have the proper types
|
||||||
# and use the overloading resolution mechanism:
|
# and use the overloading resolution mechanism:
|
||||||
var call = newNode(nkCall)
|
var call = newNode(nkCall)
|
||||||
|
var hasDistinct = false
|
||||||
call.add(newIdentNode(fn.name, fn.info))
|
call.add(newIdentNode(fn.name, fn.info))
|
||||||
for i in 1.. <fn.typ.n.len:
|
for i in 1.. <fn.typ.n.len:
|
||||||
let param = fn.typ.n.sons[i]
|
let param = fn.typ.n.sons[i]
|
||||||
let t = skipTypes(param.typ, abstractVar-{tyTypeDesc})
|
let t = skipTypes(param.typ, abstractVar-{tyTypeDesc})
|
||||||
|
if t.kind == tyDistinct or param.typ.kind == tyDistinct: hasDistinct = true
|
||||||
call.add(newNodeIT(nkEmpty, fn.info, t.baseOfDistinct))
|
call.add(newNodeIT(nkEmpty, fn.info, t.baseOfDistinct))
|
||||||
var resolved = semOverloadedCall(c, call, call, {fn.kind})
|
if hasDistinct:
|
||||||
if resolved != nil:
|
var resolved = semOverloadedCall(c, call, call, {fn.kind})
|
||||||
result = resolved.sons[0].sym
|
if resolved != nil:
|
||||||
|
result = resolved.sons[0].sym
|
||||||
|
|
|
||||||
17
tests/reject/tinvalidborrow.nim
Normal file
17
tests/reject/tinvalidborrow.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
discard """
|
||||||
|
line: 11
|
||||||
|
errormsg: "no symbol to borrow from found"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #516
|
||||||
|
|
||||||
|
type
|
||||||
|
TAtom = culong
|
||||||
|
|
||||||
|
proc `==`*(a, b: TAtom): bool {.borrow.}
|
||||||
|
|
||||||
|
var
|
||||||
|
d, e: TAtom
|
||||||
|
|
||||||
|
echo( $(d == e) )
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue