fixes #19015 [backport:1.6] (#19204)

(cherry picked from commit d584dd5b99)
This commit is contained in:
Andreas Rumpf
2021-12-04 07:42:58 +01:00
committed by narimiran
parent b614d97a2d
commit 56409c15c0
4 changed files with 11 additions and 2 deletions

View File

@@ -4,6 +4,10 @@
## Changes affecting backward compatibility
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
`experimental:flexibleOptionalParams`.
## Standard library additions and changes
## Standard library additions and changes

View File

@@ -207,7 +207,8 @@ type
strictNotNil,
overloadableEnums,
strictEffects,
unicodeOperators
unicodeOperators,
flexibleOptionalParams
LegacyFeature* = enum
allowSemcheckedAstModification,

View File

@@ -2461,7 +2461,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
if m.callee.n[f].kind != nkSym:
internalError(c.config, n[a].info, "matches")
noMatch()
if a >= firstArgBlock: f = max(f, m.callee.n.len - (n.len - a))
if flexibleOptionalParams in c.features and a >= firstArgBlock:
f = max(f, m.callee.n.len - (n.len - a))
formal = m.callee.n[f].sym
m.firstMismatch.kind = kTypeMismatch
if containsOrIncl(marker, formal.position) and container.isNil:

View File

@@ -1,3 +1,6 @@
{.experimental: "flexibleOptionalParams".}
# https://github.com/nim-lang/RFCs/issues/405
template main =