mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
fixes #4554, fixes #10900, fixes #13843, fixes #19471, fixes #19517 Instead of matching generic converters to their arguments using the full call match bindings, a new match is created for them (from which the bindings are used to instantiate the converter return type). Then when instantiating generic converters, they are matched to their argument again to get their bindings again instead of using the call bindings. This prevents generic converters which match more than once from interfering with each other's bindings.
39 lines
556 B
Nim
39 lines
556 B
Nim
# issue #10900
|
|
|
|
import std/options
|
|
|
|
type
|
|
AllTypesInModule =
|
|
bool | string | seq[int]
|
|
|
|
converter toOptional[T: AllTypesInModule](x: T): Option[T] =
|
|
some(x)
|
|
|
|
proc foo(
|
|
a: Option[bool] = none[bool](),
|
|
b: Option[string] = none[string](),
|
|
c: Option[seq[int]] = none[seq[int]]()) =
|
|
discard
|
|
|
|
# works:
|
|
foo(a = true)
|
|
foo(true)
|
|
foo(b = "asdf")
|
|
foo(c = @[1, 2, 3])
|
|
|
|
# fails:
|
|
foo(
|
|
a = true,
|
|
b = "asdf")
|
|
foo(true, "asdf")
|
|
foo(
|
|
a = true,
|
|
c = @[1, 2, 3])
|
|
foo(
|
|
b = "asdf",
|
|
c = @[1, 2, 3])
|
|
foo(
|
|
a = true,
|
|
b = "asdf",
|
|
c = @[1, 2, 3])
|