breaking change: symbol lookups in generics follows spec more closely; fixes #2664

This commit is contained in:
Araq 2015-08-07 21:28:45 +02:00
commit c733b3181e
4 changed files with 88 additions and 65 deletions

View file

@ -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)

View file

@ -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)

View 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

View 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())