mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 00:24:16 +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.
37 lines
778 B
Nim
37 lines
778 B
Nim
discard """
|
|
output: '''
|
|
int | int
|
|
int | string
|
|
int | string
|
|
'''
|
|
"""
|
|
|
|
# issue #19517
|
|
|
|
type thing [T] = object
|
|
value: T
|
|
|
|
converter asValue[T](o: thing[T]): T =
|
|
o.value
|
|
|
|
proc mycall(num, num2: int) =
|
|
echo ($(num.type) & " | " & $(num2.type))
|
|
|
|
proc mycall(num: int, str: string) =
|
|
echo ($(num.type) & " | " & $(str.type))
|
|
|
|
mycall( # This call uses asValue[int] converter automatically fine
|
|
thing[int](value: 1),
|
|
thing[int](value: 42),
|
|
)
|
|
|
|
mycall( # This gives a type error as if the converter was not defined and I tried to pass in a thing directly
|
|
thing[int](value: 2),
|
|
thing[string](value: "foo"),
|
|
)
|
|
|
|
mycall( # This can be fixed by calling the converter explicitly for everything but the first use
|
|
thing[int](value: 2),
|
|
thing[string](value: "foo").asValue,
|
|
)
|