summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semtypes.nim6
-rw-r--r--doc/manual.txt2
-rw-r--r--tests/metatype/udtcmanual.nim43
-rw-r--r--tests/types/tisopr.nim7
4 files changed, 52 insertions, 6 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 5291dbb10..a619de7ff 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -711,6 +711,12 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
     for i in 0 .. paramType.sonsLen - 2:
       result.rawAddSon newTypeS(tyAnything, c)
       # result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
+
+    if paramType.lastSon.kind == tyUserTypeClass:
+      result.kind = tyUserTypeClassInst
+      result.rawAddSon paramType.lastSon
+      return addImplicitGeneric(result)
+    
     result = instGenericContainer(c, paramType.sym.info, result,
                                   allowMetaTypes = true)
     result = newTypeWithSons(c, tyCompositeTypeClass, @[paramType, result])
diff --git a/doc/manual.txt b/doc/manual.txt
index f3602dc58..427fa2eb7 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -3441,7 +3441,7 @@ Declarative type classes are written in the following form:
       c.len is ordinal
       items(c) is iterator
       for value in c:
-        type(value) is T
+        value.type is T
 
 The type class will be matched if:
 
diff --git a/tests/metatype/udtcmanual.nim b/tests/metatype/udtcmanual.nim
new file mode 100644
index 000000000..f22bd6ac6
--- /dev/null
+++ b/tests/metatype/udtcmanual.nim
@@ -0,0 +1,43 @@
+discard """
+  output: '''1
+2
+3
+4
+5
+6
+a
+b
+t
+e
+s
+t
+'''
+"""
+
+template accept(e: expr) =
+  static: assert compiles(e)
+
+template reject(e: expr) =
+  static: assert(not compiles(e))
+
+type
+  Container[T] = generic C
+    C.len is Ordinal
+    items(c) is iterator
+    for value in C:
+      value.type is T
+
+proc takesIntContainer(c: Container[int]) =
+  for e in c: echo e
+
+takesIntContainer(@[1, 2, 3])
+reject takesIntContainer(@["x", "y"])
+
+proc takesContainer(c: Container) =
+  for e in c: echo e
+
+takesContainer(@[4, 5, 6])
+takesContainer(@["a", "b"])
+takesContainer "test"
+reject takesContainer(10)
+
diff --git a/tests/types/tisopr.nim b/tests/types/tisopr.nim
index f173b93f4..3c2b9ee5e 100644
--- a/tests/types/tisopr.nim
+++ b/tests/types/tisopr.nim
@@ -1,11 +1,8 @@
 discard """
-  output: '''true
-true
-false
-yes'''
+  output: '''true true false yes'''
 """
 
-proc IsVoid[T](): string = 
+proc IsVoid[T](): string =
   when T is void:
     result = "yes"
   else: