From 97f54745459b8651b7a38c174b3a8135224ebd09 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 19 Jul 2024 05:53:35 -0600 Subject: [PATCH] fix generics treating symchoice symbols as uninstantiated (#23860) fixes #23853 Since #22610 generics turns the `Name` in the `GT.Name` expression in the test code into a sym choice. The problem is when the compiler tries to instantiate `GT.Name` it also instantiates the sym choice symbols. `Name` has type `template (E: type ExtensionField)` which contains the unresolved generic type `ExtensionField`, which the compiler mistakes as an uninstantiated node, when it's just part of the type of the template. The compilation of the node itself and hence overloading will handle the instantiation of the proc, so we avoid instantiating it in `semtypinst`, similar to how the first nodes of call nodes aren't instantiated. --- compiler/semtypinst.nim | 6 ++- tests/generics/t23853.nim | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/generics/t23853.nim diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index f0ce8d76f0c7..e87a4939a2f1 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -132,9 +132,13 @@ proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode = else: replaceTypeVarsS(cl, n.sym, replaceTypeVarsT(cl, n.sym.typ)) let isCall = result.kind in nkCallKinds + # 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..