fixes #1011
This commit is contained in:
parent
d80d8aa74d
commit
eb99c27bd0
3 changed files with 49 additions and 3 deletions
|
|
@ -82,7 +82,37 @@ proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
|||
else:
|
||||
result = semGenericStmtSymbol(c, n, s)
|
||||
# else: leave as nkIdent
|
||||
|
||||
proc newDot(n, b: PNode): PNode =
|
||||
result = newNodeI(nkDotExpr, n.info)
|
||||
result.add(n.sons[0])
|
||||
result.add(b)
|
||||
|
||||
proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||
ctx: var TIntSet): PNode =
|
||||
assert n.kind == nkDotExpr
|
||||
let luf = if withinMixin notin flags: {checkUndeclared} else: {}
|
||||
|
||||
var s = qualifiedLookUp(c, n, luf)
|
||||
if s != nil:
|
||||
result = semGenericStmtSymbol(c, n, s)
|
||||
else:
|
||||
result = n
|
||||
let n = n[1]
|
||||
let ident = considerQuotedIdent(n)
|
||||
var s = searchInScopes(c, ident)
|
||||
if s != nil:
|
||||
if withinBind in flags:
|
||||
result = newDot(result, symChoice(c, n, s, scClosed))
|
||||
elif s.name.id in ctx:
|
||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
||||
else:
|
||||
let sym = semGenericStmtSymbol(c, n, s)
|
||||
if sym.kind == nkSym:
|
||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
||||
else:
|
||||
result = newDot(result, sym)
|
||||
|
||||
proc semGenericStmt(c: PContext, n: PNode,
|
||||
flags: TSemGenericFlags, ctx: var TIntSet): PNode =
|
||||
result = n
|
||||
|
|
@ -91,10 +121,11 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
of nkIdent, nkAccQuoted:
|
||||
result = lookup(c, n, flags, ctx)
|
||||
of nkDotExpr:
|
||||
let luf = if withinMixin notin flags: {checkUndeclared} else: {}
|
||||
var s = qualifiedLookUp(c, n, luf)
|
||||
if s != nil: result = semGenericStmtSymbol(c, n, s)
|
||||
#let luf = if withinMixin notin flags: {checkUndeclared} else: {}
|
||||
#var s = qualifiedLookUp(c, n, luf)
|
||||
#if s != nil: result = semGenericStmtSymbol(c, n, s)
|
||||
# XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
|
||||
result = fuzzyLookup(c, n, flags, ctx)
|
||||
of nkEmpty, nkSym..nkNilLit:
|
||||
# see tests/compile/tgensymgeneric.nim:
|
||||
# We need to open the gensym'ed symbol again so that the instantiation
|
||||
|
|
|
|||
8
tests/generics/mdotlookup.nim
Normal file
8
tests/generics/mdotlookup.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
proc baz(o: any): int = 5 # if bar is exported, it works
|
||||
|
||||
type MyObj = object
|
||||
x: int
|
||||
|
||||
proc foo*(b: any) =
|
||||
var o: MyObj
|
||||
echo b.baz, " ", o.x.baz, " ", b.baz()
|
||||
7
tests/generics/tdotlookup.nim
Normal file
7
tests/generics/tdotlookup.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
discard """
|
||||
output: '''5 5 5'''
|
||||
"""
|
||||
|
||||
import mdotlookup
|
||||
|
||||
foo(7)
|
||||
Loading…
Add table
Add a link
Reference in a new issue