Skip to content

Commit

Permalink
make experimental feature for now
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Oct 16, 2024
1 parent b409ca4 commit 21f8c77
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions compiler/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ define:useStdoutAsStdmsg
@if nimHasVtables:
experimental:vtables
@end

@if nimHasTypeBoundOps:
experimental:typeBoundOps
@end
1 change: 1 addition & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type
# alternative to above:
genericsOpenSym
vtables
typeBoundOps

LegacyFeature* = enum
allowSemcheckedAstModification,
Expand Down
20 changes: 11 additions & 9 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ proc initCandidateSymbols(c: PContext, headSymbol: PNode,
result.add((paramTyp.n.sym, o.lastOverloadScope))

symx = nextOverloadIter(o, c, headSymbol)
if headSymbol.kind != nkDotExpr: # qualified, maybe whitelist ident/opensymchoice?
# add all type bound ops with this specific name
# may be slow to do this for every single call, but the nominal types
# imply a straightforward match
let name = considerQuotedIdent(c, headSymbol)
for boundOp in c.graph.typeBoundOps.getOrDefault(name, @[]):
if boundOp.id notin symMarker:
# no need to add to symMarker, type bound ops should be unique already
result.add((boundOp, -2))
if typeBoundOps in c.features:
# TODO move this to happen after `prepareOperand` and per type
if headSymbol.kind != nkDotExpr: # qualified, maybe whitelist ident/opensymchoice?
# add all type bound ops with this specific name
# may be slow to do this for every single call, but the nominal types
# imply a straightforward match
let name = considerQuotedIdent(c, headSymbol)
for boundOp in c.graph.typeBoundOps.getOrDefault(name, @[]):
if boundOp.id notin symMarker:
# no need to add to symMarker, type bound ops should be unique already
result.add((boundOp, -2))
if result.len > 0:
best = initCandidate(c, result[0].s, initialBinding,
result[0].scope, diagnostics)
Expand Down
1 change: 1 addition & 0 deletions tests/config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ when not defined(testsConciseTypeMismatch):
switch("legacy", "verboseTypeMismatch")
switch("experimental", "vtables")
switch("experimental", "openSym")
switch("experimental", "typeBoundOps")

0 comments on commit 21f8c77

Please sign in to comment.