New approach

This commit is contained in:
cooldome 2018-06-12 00:20:08 +01:00
commit 1b7cf3df51
3 changed files with 27 additions and 32 deletions

View file

@ -36,14 +36,6 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
# we apply the last pattern first, so that pattern overriding is possible; # we apply the last pattern first, so that pattern overriding is possible;
# however the resulting AST would better not trigger the old rule then # however the resulting AST would better not trigger the old rule then
# anymore ;-) # anymore ;-)
if c.patterns.len > 0:
# temporary disable converters
var ctx_converters: TSymSeq
shallowCopy(ctx_converters, c.converters)
c.converters = @[]
defer: shallowCopy(c.converters, ctx_converters)
for i in countdown(c.patterns.len-1, 0): for i in countdown(c.patterns.len-1, 0):
let pattern = c.patterns[i] let pattern = c.patterns[i]
if not isNil(pattern): if not isNil(pattern):

View file

@ -77,7 +77,7 @@ proc checkTypes(c: PPatternContext, p: PSym, n: PNode): bool =
if isNil(n.typ): if isNil(n.typ):
result = p.typ.kind in {tyVoid, tyStmt} result = p.typ.kind in {tyVoid, tyStmt}
else: else:
result = sigmatch.argtypeMatches(c.c, p.typ, n.typ) result = sigmatch.argtypeMatches(c.c, p.typ, n.typ, from_hlo = true)
proc isPatternParam(c: PPatternContext, p: PNode): bool {.inline.} = proc isPatternParam(c: PPatternContext, p: PNode): bool {.inline.} =
result = p.kind == nkSym and p.sym.kind == skParam and p.sym.owner == c.owner result = p.kind == nkSym and p.sym.kind == skParam and p.sym.owner == c.owner

View file

@ -2359,14 +2359,17 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
for t in m.inferredTypes: for t in m.inferredTypes:
if t.sonsLen > 1: t.sons.setLen 1 if t.sonsLen > 1: t.sons.setLen 1
proc argtypeMatches*(c: PContext, f, a: PType): bool = proc argtypeMatches*(c: PContext, f, a: PType, from_hlo = false): bool =
var m: TCandidate var m: TCandidate
initCandidate(c, m, f) initCandidate(c, m, f)
let res = paramTypesMatch(m, f, a, ast.emptyNode, nil) let res = paramTypesMatch(m, f, a, ast.emptyNode, nil)
#instantiateGenericConverters(c, res, m) #instantiateGenericConverters(c, res, m)
# XXX this is used by patterns.nim too; I think it's better to not # XXX this is used by patterns.nim too; I think it's better to not
# instantiate generic converters for that # instantiate generic converters for that
result = res != nil if not from_hlo:
res != nil
else:
res != nil and m.convMatches == 0 and m.intConvMatches in [0, 256]
proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo; proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
op: TTypeAttachedOp; col: int): PSym {.procvar.} = op: TTypeAttachedOp; col: int): PSym {.procvar.} =