From 9e8e47df5495df6cf0a18f62cff68d0dbe08e72a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:54:09 +0800 Subject: [PATCH 1/4] fixes #22054; codegen for var tuples conv --- compiler/transf.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/transf.nim b/compiler/transf.nim index 0176a108714dc..fba6e69581648 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -802,7 +802,14 @@ proc transformArrayAccess(c: PTransf, n: PNode): PNode = result = n else: result = newTransNode(n) - for i in 0.. Date: Wed, 14 Jun 2023 16:04:51 +0800 Subject: [PATCH 2/4] rethink fixes --- compiler/sigmatch.nim | 5 +++-- compiler/transf.nim | 9 +-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 8f396840eb5e2..d34c88ec09e2e 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 in {skTemplate, skMacro}: 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``: diff --git a/compiler/transf.nim b/compiler/transf.nim index fba6e69581648..0176a108714dc 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -802,14 +802,7 @@ proc transformArrayAccess(c: PTransf, n: PNode): PNode = result = n else: result = newTransNode(n) - if n[0].kind in {nkHiddenStdConv, nkHiddenSubConv} and - n[0].typ != nil and - n[0].typ.skipTypes(abstractInst+{tyVar}).kind == tyTuple: - # do not skip conv for tuples # bug #22054 - result[0] = transform(c, n[0]) - else: - result[0] = transform(c, skipConv(n[0])) - for i in 1.. Date: Wed, 14 Jun 2023 16:09:10 +0800 Subject: [PATCH 3/4] add test cases --- tests/tuples/ttuples_various.nim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/tuples/ttuples_various.nim b/tests/tuples/ttuples_various.nim index dc060da1e24ea..97bc70bd286d1 100644 --- a/tests/tuples/ttuples_various.nim +++ b/tests/tuples/ttuples_various.nim @@ -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 From 480a090c8d99431fce07f6508689f2d18141181b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 14 Jun 2023 16:50:30 +0800 Subject: [PATCH 4/4] templates only --- compiler/sigmatch.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index d34c88ec09e2e..eeaac471e6a9e 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2203,7 +2203,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, let ff = skipTypes(f, abstractVar-{tyTypeDesc}) if (ff.kind == tyTuple or (arg.typ != nil and skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple)) and - m.calleeSym != nil and m.calleeSym.kind in {skTemplate, skMacro}: + 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``: