summary refs log tree commit diff stats
path: root/compiler/seminst.nim
diff options
context:
space:
mode:
authorzah <zahary@gmail.com>2018-03-24 16:28:09 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-03-24 15:28:09 +0100
commit121b9e26fb9d1ae6037c806dbb12a3ae0e26ded6 (patch)
tree94e8a59c483046c06634191ddb75f71f10b2d821 /compiler/seminst.nim
parent2e7a0e1cdd1c942df9cfb0310751b7f1f0190f02 (diff)
downloadNim-121b9e26fb9d1ae6037c806dbb12a3ae0e26ded6.tar.gz
Static[T] fixes (#7333)
* fix the usage of unresolved static[T] parameters in proc signatures
* fix tsametype and tmacrogenerics
* Allow creating composite type classes with concepts and using them in type signatures
* Allow integers to be used in ident concatenations
* Support using imported C++ generic types in proc signatures
* fixes #7230
* closes #7379
* re-enable some metatype tests
Diffstat (limited to 'compiler/seminst.nim')
-rw-r--r--compiler/seminst.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index acea9330b..7fedaca5b 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -174,6 +174,8 @@ proc sideEffectsCheck(c: PContext, s: PSym) =
 
 proc instGenericContainer(c: PContext, info: TLineInfo, header: PType,
                           allowMetaTypes = false): PType =
+  internalAssert header.kind == tyGenericInvocation
+
   var
     typeMap: LayeredIdTable
     cl: TReplTypeVars
@@ -185,7 +187,35 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType,
   cl.info = info
   cl.c = c
   cl.allowMetaTypes = allowMetaTypes
+
+  # We must add all generic params in scope, because the generic body
+  # may include tyFromExpr nodes depending on these generic params.
+  # XXX: This looks quite similar to the code in matchUserTypeClass,
+  # perhaps the code can be extracted in a shared function.
+  openScope(c)
+  let genericTyp = header.base
+  for i in 0 .. (genericTyp.len - 2):
+    let genParam = genericTyp[i]
+    var param: PSym
+
+    template paramSym(kind): untyped =
+        newSym(kind, genParam.sym.name, genericTyp.sym, genParam.sym.info)
+
+    if genParam.kind == tyStatic:
+      param = paramSym skConst
+      param.ast = header[i+1].n
+      param.typ = header[i+1]
+    else:
+      param = paramSym skType
+      param.typ = makeTypeDesc(c, header[i+1])
+
+    # this scope was not created by the user,
+    # unused params shoudn't be reported.
+    param.flags.incl sfUsed
+    addDecl(c, param)
+
   result = replaceTypeVarsT(cl, header)
+  closeScope(c)
 
 proc instantiateProcType(c: PContext, pt: TIdTable,
                          prc: PSym, info: TLineInfo) =