Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #22049; fixes #22054; no more implicit tuple conversions for templates #22094

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2201,8 +2201,9 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
inc(m.exactMatches)
result = arg
let ff = skipTypes(f, abstractVar-{tyTypeDesc})
if ff.kind == tyTuple or
(arg.typ != nil and skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple):
if (ff.kind == tyTuple or
(arg.typ != nil and skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple)) and
m.calleeSym != nil and m.calleeSym.kind == skTemplate:
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
of isNone:
# do not do this in ``typeRel`` as it then can't infer T in ``ref T``:
Expand Down
26 changes: 26 additions & 0 deletions tests/tuples/ttuples_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,29 @@ block tuple_with_seq:
echo s
(s, 7)
t = test(t.a)

block: # bug #22049
type A = object
field: tuple[a, b, c: seq[int]]

func value(v: var A): var tuple[a, b, c: seq[int]] =
v.field
template get(v: A): tuple[a, b, c: seq[int]] = v.value

var v = A(field: (@[1], @[2], @[3]))
var (a, b, c) = v.get()

doAssert a == @[1]
doAssert b == @[2]
doAssert c == @[3]

block: # bug #22054
type A = object
field: tuple[a: int]

func value(v: var A): var tuple[a: int] =
v.field
template get(v: A): tuple[a: int] = v.value

var v = A(field: (a: 1314))
doAssert get(v)[0] == 1314