breaking change: symbol lookups in generics follows spec more closely; fixes #2664
This commit is contained in:
parent
2e4b59f3d3
commit
c733b3181e
4 changed files with 88 additions and 65 deletions
|
|
@ -141,11 +141,13 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
elif s.name.id in ctx.toMixin:
|
elif s.name.id in ctx.toMixin:
|
||||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
||||||
else:
|
else:
|
||||||
let sym = semGenericStmtSymbol(c, n, s, ctx)
|
let syms = semGenericStmtSymbol(c, n, s, ctx)
|
||||||
if sym.kind == nkSym:
|
if syms.kind == nkSym:
|
||||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
let choice = symChoice(c, n, s, scForceOpen)
|
||||||
|
choice.kind = nkClosedSymChoice
|
||||||
|
result = newDot(result, choice)
|
||||||
else:
|
else:
|
||||||
result = newDot(result, sym)
|
result = newDot(result, syms)
|
||||||
|
|
||||||
proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
|
proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
|
||||||
let s = newSymS(skUnknown, getIdentNode(n), c)
|
let s = newSymS(skUnknown, getIdentNode(n), c)
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,10 @@ proc `$`*[A, B](t: Table[A, B]): string =
|
||||||
## The `$` operator for hash tables.
|
## The `$` operator for hash tables.
|
||||||
dollarImpl()
|
dollarImpl()
|
||||||
|
|
||||||
|
proc hasKey*[A, B](t: TableRef[A, B], key: A): bool =
|
||||||
|
## returns true iff `key` is in the table `t`.
|
||||||
|
result = t[].hasKey(key)
|
||||||
|
|
||||||
template equalsImpl() =
|
template equalsImpl() =
|
||||||
if s.counter == t.counter:
|
if s.counter == t.counter:
|
||||||
# different insertion orders mean different 'data' seqs, so we have
|
# different insertion orders mean different 'data' seqs, so we have
|
||||||
|
|
@ -293,10 +297,6 @@ proc hasKeyOrPut*[A, B](t: var TableRef[A, B], key: A, val: B): bool =
|
||||||
## returns true iff `key` is in the table, otherwise inserts `value`.
|
## returns true iff `key` is in the table, otherwise inserts `value`.
|
||||||
t[].hasKeyOrPut(key, val)
|
t[].hasKeyOrPut(key, val)
|
||||||
|
|
||||||
proc hasKey*[A, B](t: TableRef[A, B], key: A): bool =
|
|
||||||
## returns true iff `key` is in the table `t`.
|
|
||||||
result = t[].hasKey(key)
|
|
||||||
|
|
||||||
proc contains*[A, B](t: TableRef[A, B], key: A): bool =
|
proc contains*[A, B](t: TableRef[A, B], key: A): bool =
|
||||||
## alias of `hasKey` for use with the `in` operator.
|
## alias of `hasKey` for use with the `in` operator.
|
||||||
return hasKey[A, B](t, key)
|
return hasKey[A, B](t, key)
|
||||||
|
|
|
||||||
10
tests/generics/mclosed_sym.nim
Normal file
10
tests/generics/mclosed_sym.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
type R* = object
|
||||||
|
|
||||||
|
type Data*[T] = object
|
||||||
|
d*: T
|
||||||
|
|
||||||
|
proc same(r:R, d:int) = echo "TEST2"
|
||||||
|
|
||||||
|
proc doIt*(d:Data, r:R) =
|
||||||
|
r.same(1) # Expecting this to invoke the local `same()` method
|
||||||
11
tests/generics/tclosed_sym.nim
Normal file
11
tests/generics/tclosed_sym.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
output: "TEST2"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #2664
|
||||||
|
|
||||||
|
import mclosed_sym
|
||||||
|
|
||||||
|
proc same(r:R, d:int) = echo "TEST1"
|
||||||
|
|
||||||
|
doIt(Data[int](d:123), R())
|
||||||
Loading…
Add table
Add a link
Reference in a new issue