Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test allowing types in symchoices by giving them typedesc type #23966

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 9 additions & 5 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3121,12 +3121,16 @@ proc resolveIdentToSym(c: PContext, n: PNode, resultNode: var PNode,
# unambiguous, or we don't care about ambiguity
result = candidates[0]
else:
# ambiguous symbols have 1 last chance as a symchoice,
# but type symbols cannot participate in symchoices
# ambiguous symbols have 1 last chance as a symchoice
var choice = newNodeIT(nkClosedSymChoice, n.info, newTypeS(tyNone, c))
for c in candidates:
if c.kind notin {skType, skModule, skPackage}:
choice.add newSymNode(c, n.info)
for cand in candidates:
case cand.kind
of skModule, skPackage:
discard
of skType:
choice.add newSymNodeTypeDesc(cand, c.idgen, n.info)
else:
choice.add newSymNode(cand, n.info)
if choice.len == 0:
# we know candidates.len > 1, we just couldn't put any in a symchoice
errorUseQualifier(c, n.info, candidates)
Expand Down
4 changes: 2 additions & 2 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
result = newSymNode(s, n.info)
onUse(n.info, s)
else:
if s.kind in {skType, skVar, skLet, skConst}:
if s.kind in {skVar, skLet, skConst}:
discard qualifiedLookUp(c.c, n, {checkAmbiguity, checkModule})
result = semTemplSymbol(c.c, n, s, c.noGenSym > 0)
of nkBind:
Expand Down Expand Up @@ -572,7 +572,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
elif contains(c.toMixin, s.name.id):
return symChoice(c.c, n, s, scForceOpen, c.noGenSym > 0)
else:
if s.kind in {skType, skVar, skLet, skConst}:
if s.kind in {skVar, skLet, skConst}:
discard qualifiedLookUp(c.c, n, {checkAmbiguity, checkModule})
return semTemplSymbol(c.c, n, s, c.noGenSym > 0)
if n.kind == nkDotExpr:
Expand Down
5 changes: 4 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
result = paramTypesMatchAux(m, f, a, arg, argOrig)
else:
# symbol kinds that don't participate in symchoice type disambiguation:
let matchSet = {low(TSymKind)..high(TSymKind)} - {skModule, skPackage, skType}
let matchSet = {low(TSymKind)..high(TSymKind)} - {skModule, skPackage}

var best = -1
result = arg
Expand Down Expand Up @@ -2422,6 +2422,9 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
if arg[i].sym.kind in matchSet:
copyCandidate(z, m)
z.callee = arg[i].typ
if arg[i].sym.kind == skType and z.callee.kind != tyTypeDesc:
z.callee = newType(tyTypeDesc, c.idgen, arg[i].sym.owner)
z.callee.addSonSkipIntLit(arg[i].sym.typ, c.idgen)
if tfUnresolved in z.callee.flags: continue
z.calleeSym = arg[i].sym
z.calleeScope = cmpScopes(m.c, arg[i].sym)
Expand Down
1 change: 1 addition & 0 deletions tests/overload/m23898_1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type K* = object
4 changes: 4 additions & 0 deletions tests/overload/m23898_2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ./m23898_1
export m23898_1
template K*(kind: static int): auto = typedesc[m23898_1.K]
template B*(kind: static int): auto = typedesc[m23898_1.K]
8 changes: 8 additions & 0 deletions tests/overload/t23898.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ./m23898_2
discard default(B(0)) # compiles
discard default(m23898_2.B(0)) # compiles
discard default(K(0)) # compiles
template r() =
discard default(B(0)) # compiles
discard default(m23898_2.B(0)) # compiles
discard default(K(0)) # does not compile
Loading