fix #587
This commit is contained in:
parent
249dd70273
commit
ee1b0d8c67
4 changed files with 52 additions and 6 deletions
|
|
@ -711,6 +711,12 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
for i in 0 .. paramType.sonsLen - 2:
|
for i in 0 .. paramType.sonsLen - 2:
|
||||||
result.rawAddSon newTypeS(tyAnything, c)
|
result.rawAddSon newTypeS(tyAnything, c)
|
||||||
# result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
|
# 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,
|
result = instGenericContainer(c, paramType.sym.info, result,
|
||||||
allowMetaTypes = true)
|
allowMetaTypes = true)
|
||||||
result = newTypeWithSons(c, tyCompositeTypeClass, @[paramType, result])
|
result = newTypeWithSons(c, tyCompositeTypeClass, @[paramType, result])
|
||||||
|
|
|
||||||
|
|
@ -3441,7 +3441,7 @@ Declarative type classes are written in the following form:
|
||||||
c.len is ordinal
|
c.len is ordinal
|
||||||
items(c) is iterator
|
items(c) is iterator
|
||||||
for value in c:
|
for value in c:
|
||||||
type(value) is T
|
value.type is T
|
||||||
|
|
||||||
The type class will be matched if:
|
The type class will be matched if:
|
||||||
|
|
||||||
|
|
|
||||||
43
tests/metatype/udtcmanual.nim
Normal file
43
tests/metatype/udtcmanual.nim
Normal file
|
|
@ -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)
|
||||||
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''true
|
output: '''true true false yes'''
|
||||||
true
|
|
||||||
false
|
|
||||||
yes'''
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc IsVoid[T](): string =
|
proc IsVoid[T](): string =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue