From a031866c8d0f668ad8326d8b9e6f51bf33bb4fdf Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 19 Aug 2024 14:49:48 +0300 Subject: [PATCH] this is disgusting --- compiler/semexprs.nim | 27 +++++-- compiler/semtypinst.nim | 73 +++++++++++++------ .../generics/tuninstantiatedgenericcalls.nim | 2 +- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 2e90dffbf1aec..6b70f7fd026a3 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1137,6 +1137,12 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType result.flags.incl nfExplicitCall for i in 1.. 0: + # don't make assumptions, entire expression needs to be tyFromExpr + n[0].typ = nil + result = semGenericStmt(c, n) + result.typ = makeTypeFromExpr(c, result.copyTree) + return else: n[0] = n0 else: @@ -1480,17 +1486,26 @@ proc tryReadingGenericParam(c: PContext, n: PNode, i: PIdent, t: PType): PNode = of tyTypeParamsHolders: result = readTypeParameter(c, t, i, n.info) if result == c.graph.emptyNode: - result = n - n.typ = makeTypeFromExpr(c, n.copyTree) + if true or c.inGenericContext > 0: + result = semGenericStmt(c, n) + result.typ = makeTypeFromExpr(c, result.copyTree) + else: + result = nil of tyUserTypeClasses: if t.isResolvedUserTypeClass: result = readTypeParameter(c, t, i, n.info) else: - n.typ = makeTypeFromExpr(c, copyTree(n)) - result = n + if true or c.inGenericContext > 0: + result = semGenericStmt(c, n) + result.typ = makeTypeFromExpr(c, copyTree(result)) + else: + result = nil of tyGenericParam, tyAnything: - n.typ = makeTypeFromExpr(c, copyTree(n)) - result = n + if true or c.inGenericContext > 0: + result = semGenericStmt(c, n) + result.typ = makeTypeFromExpr(c, copyTree(result)) + else: + result = nil else: result = nil diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index cdc3b587932a8..4d74ebd636b7b 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -118,17 +118,6 @@ proc replaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType = result = replaceTypeVarsTAux(cl, t) checkMetaInvariants(cl, result) -proc isLikeGenericInvocation(n: PNode): int = - result = -1 - if n.kind in nkCallKinds and - (let ident = n[0].getPIdent; ident != nil and ident.s == "[]"): - result = 1 - elif n.kind == nkBracketExpr: - result = 0 - if result >= 0 and (result > n.len or - n[result].typ == nil or n[result].typ.kind != tyTypeDesc): - result = -1 - proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode = let t = replaceTypeVarsT(cl, n.typ) if t != nil and t.kind == tyStatic and t.n != nil: @@ -142,20 +131,58 @@ proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode = replaceTypeVarsS(cl, n.sym, result.typ) else: replaceTypeVarsS(cl, n.sym, replaceTypeVarsT(cl, n.sym.typ)) - let isCall = result.kind in nkCallKinds - let ignoreUntil = isLikeGenericInvocation(n) - let isGenericInvocation = ignoreUntil >= 0 - # don't try to instantiate symchoice symbols, they can be - # generic procs which the compiler will think are uninstantiated - # because their type will contain uninstantiated params - let isSymChoice = result.kind in nkSymChoices - for i in 0.. 1 and + (n[1].typ != nil and n[1].typ.kind == tyTypeDesc) + if ignoreFirst: + result.add(n[0]) + else: + result.add(prepareNode(cl, n[0])) + if n.len > 1: + if ignoreSecond: + result.add(n[1]) + else: + result.add(prepareNode(cl, n[1])) + for i in 2..= 2 + result.add(prepareNode(cl, n[0])) + result.add(n[1]) + for i in 2..