Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/nimony/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6763,6 +6763,27 @@ proc semTableConstructor(c: var SemContext; it: var Item; flags: set[SemFlag]) =
it.typ = item.typ
inc it.n

proc expandSymChoice(c: var SemContext; n: var Cursor) =
let info = n.info
takeToken c, n
assert n.kind == Symbol
var name = pool.syms[n.symId]
extractBasename(name)
var marker = initHashSet[SymId]()
while n.kind != ParRi:
assert n.kind == Symbol
marker.incl n.symId
takeToken c, n
addSymChoiceSyms(c, pool.strings.getOrIncl(name), marker, info)
takeParRi c, n

proc semSymChoice(c: var SemContext; it: var Item; flags: set[SemFlag] = {}) =
if it.n.exprKind == OchoiceX:
# could restrict to callees
expandSymChoice c, it.n
else:
takeTree c, it.n

proc semExpr(c: var SemContext; it: var Item; flags: set[SemFlag] = {}) =
case it.n.kind
of IntLit:
Expand Down Expand Up @@ -7027,7 +7048,7 @@ proc semExpr(c: var SemContext; it: var Item; flags: set[SemFlag] = {}) =
of FieldsX, FieldpairsX, InternalFieldPairsX:
takeTree c, it.n
of OchoiceX, CchoiceX:
takeTree c, it.n
semSymChoice c, it
of HaddrX, HderefX:
takeToken c, it.n
# this is exactly what we need here as these operators have the same
Expand Down
16 changes: 16 additions & 0 deletions src/nimony/sembasics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ proc buildSymChoice*(c: var SemContext; identifier: StrId; info: PackedLineInfo;
c.dest.shrink oldLen
c.dest.add identToken(identifier, info)

proc addSymChoiceSyms*(c: var SemContext; identifier: StrId; marker: var HashSet[SymId]; info: PackedLineInfo) =
# like rawBuildSymChoice but adds to an existing symchoice, ignoring duplicates
var it = c.currentScope
while it != nil:
for sym in it.tab.getOrDefault(identifier):
if not marker.containsOrIncl(sym.name):
c.dest.addSymUse sym, info
it = it.up
# mirror considerImportedSymbols:
for moduleId in c.importTab.getOrDefault(identifier):
# prevent copies
let candidates = addr c.importedModules[moduleId].iface[identifier]
for defId in candidates[]:
if not marker.containsOrIncl(defId):
c.dest.add symToken(defId, info)

proc isDeclared*(c: var SemContext; name: StrId): bool =
var scope = c.currentScope
while scope != nil:
Expand Down
12 changes: 12 additions & 0 deletions tests/nimony/lookups/tcrossmoduleoverload.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import std / syncio

type
MyS = distinct string

proc write*(f: File; s: MyS) = write f, string(s)

proc main =
var s90 = MyS"abc"
echo s90

main()