mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 08:34:20 +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.
42 lines
683 B
Nim
42 lines
683 B
Nim
discard """
|
|
output: '''
|
|
Converting (int, int) to A
|
|
Converting (int, int) to A
|
|
Checked: A
|
|
Checked: A
|
|
Checked: A
|
|
Converting (A, A) to A
|
|
Converting (int, int) to A
|
|
Checked: A
|
|
Checked: A
|
|
Checked: A
|
|
Converting (A, A) to A
|
|
Converting (A, A) to A
|
|
Checked: A
|
|
Checked: A
|
|
Checked: A
|
|
'''
|
|
"""
|
|
|
|
# issue #19471
|
|
|
|
type A = ref object
|
|
|
|
converter toA(x: tuple): A =
|
|
echo "Converting ", x.type, " to A"
|
|
A()
|
|
|
|
proc check(a: A) =
|
|
echo "Checked: ", a.type
|
|
|
|
proc mux(a: A, b: A, c: A) =
|
|
check(a)
|
|
check(b)
|
|
check(c)
|
|
|
|
let a = A()
|
|
|
|
mux(a, (0, 0), (1, 1)) # both tuples are (int, int)
|
|
mux(a, (a, a), (1, 1)) # one tuple is (A, A), another (int, int)
|
|
mux(a, (a, a), (a, a)) # both tuples are (A, A)
|