diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 55fcc43bd9..700022b61c 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -15,6 +15,8 @@ import magicsys, idents, lexer, options, parampatterns, trees, linter, lineinfos, lowerings, modulegraphs, concepts, layeredtable +import typeallowed + import std/[intsets, strutils, tables] when defined(nimPreviewSlimSystem): @@ -123,6 +125,38 @@ proc initCandidate*(ctx: PContext, callee: PType): TCandidate = result.calleeSym = nil result.bindings = initLayeredTypeMap() +proc materializeTupleViewType(t: PType; idgen: IdGenerator): PType = + case t.kind + of tyVar, tyLent: + result = materializeTupleViewType(t.elementType, idgen) + of tyTuple: + if classifyViewType(t) == noView: + result = t + else: + result = copyType(t, idgen, t.owner) + for i in 0.. ", val - put(c.bindings, key, val.skipIntLit(c.c.idgen)) + + let normalized = val.skipIntLit(c.c.idgen) + if normalized.kind == tyTuple and classifyViewType(normalized) != noView: + put(c.bindings, key, materializeTupleViewType(normalized, c.c.idgen)) + else: + put(c.bindings, key, normalized) proc typeRel*(c: var TCandidate, f, aOrig: PType, flags: TTypeRelFlags = {}): TTypeRelation @@ -2200,7 +2239,16 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate, if result.typ == nil: internalError(c.graph.config, arg.info, "implicitConv") result.add c.graph.emptyNode - if arg.typ != nil and arg.typ.kind == tyLent: + let targetTuple = result.typ.skipTypes({tyVar, tyGenericInst, tyAlias, tySink, tyDistinct, tyInferred}) + let sourceTuple = + if arg.typ != nil: + arg.typ.skipTypes({tyGenericInst, tyAlias, tySink, tyDistinct, tyInferred}) + else: + nil + if sourceTuple != nil and sourceTuple.kind == tyTuple and targetTuple.kind == tyTuple and + classifyViewType(arg.typ) != noView and classifyViewType(result.typ) == noView: + result.add materializeTupleViewArg(c, targetTuple, arg) + elif arg.typ != nil and arg.typ.kind == tyLent: let a = newNodeIT(nkHiddenDeref, arg.info, arg.typ.elementType) a.add arg result.add a