diff options
author | metagn <metagngn@gmail.com> | 2024-09-10 13:19:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 12:19:39 +0200 |
commit | baec1955b5453ec71fc12355142dd9a813fa02fb (patch) | |
tree | 0c5e4283b7cc857a93319b9635ce6adb7b2861fa /compiler | |
parent | 21771765a2c1f1fc86d87ad6e032d4050d8a651b (diff) | |
download | Nim-baec1955b5453ec71fc12355142dd9a813fa02fb.tar.gz |
don't instantiate generic body type symbols in generic expressions (#24092)
fixes #24090 Generic body types are normally a sign of an uninstantiated type, and so give errors when trying to instantiate them. However when instantiating free user expressions like the nodes of `tyFromExpr`, generic default params, static values etc, they can be used as arguments to macros or templates etc (as in the issue). So, we don't try to instantiate generic body type symbols at all in free expressions such as these (but not in for example type nodes), and avoid the error. In the future there should be a "concrete type" check for generic body types different from the check in type instantiation to deal with things like #24091, if we do want to allow this use of them.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semtypinst.nim | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 3c39e846e..b4fc319ec 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -119,6 +119,11 @@ proc replaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType = checkMetaInvariants(cl, result) proc prepareNode*(cl: var TReplTypeVars, n: PNode): PNode = + ## instantiates a given generic expression, not a type node + if n.kind == nkSym and n.sym.kind == skType and + n.sym.typ != nil and n.sym.typ.kind == tyGenericBody: + # generic body types are allowed as user expressions, see #24090 + return n let t = replaceTypeVarsT(cl, n.typ) if t != nil and t.kind == tyStatic and t.n != nil: return if tfUnresolved in t.flags: prepareNode(cl, t.n) |