iterable[T] (#17196)

* fix failing test toSeq in manual which now works
* changelog
* reject proc fn(a: iterable)
* add iterable to spec
* remove MCS/UFCS limitation that now works
This commit is contained in:
Timothee Cour 2021-04-11 07:25:41 -05:00 • committed by GitHub
commit ceadf54d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 254 additions and 40 deletions

View file

@ -62,7 +62,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
best, alt: var TCandidate,
errors: var CandidateErrors,
diagnosticsFlag: bool,
errorsEnabled: bool) =
errorsEnabled: bool, flags: TExprFlags) =
var o: TOverloadIter
var sym = initOverloadIter(o, c, headSymbol)
var scope = o.lastOverloadScope
@ -95,7 +95,11 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
matches(c, n, orig, z)
if z.state == csMatch:
# little hack so that iterators are preferred over everything else:
if sym.kind == skIterator: inc(z.exactMatches, 200)
if sym.kind == skIterator:
if not (efWantIterator notin flags and efWantIterable in flags):
inc(z.exactMatches, 200)
else:
dec(z.exactMatches, 200)
case best.state
of csEmpty, csNoMatch: best = z
of csMatch:
@ -356,7 +360,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
template pickBest(headSymbol) =
pickBestCandidate(c, headSymbol, n, orig, initialBinding,
filter, result, alt, errors, efExplain in flags,
errorsEnabled)
errorsEnabled, flags)
pickBest(f)
let overloadsState = result.state