diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-06-19 20:07:26 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-06-20 11:29:42 +0200 |
commit | 8f4b3743277119a0ec231738fdd3931476c186d9 (patch) | |
tree | 7538d3bb8d2a55112e1196df5e2170f99ba08c47 /tests | |
parent | b199c5af4ef76c44bef0ea50bbe163410bd8fdaf (diff) | |
download | Nim-8f4b3743277119a0ec231738fdd3931476c186d9.tar.gz |
Fix #4020; Better handling of templates within concepts
Diffstat (limited to 'tests')
-rw-r--r-- | tests/concepts/templatesinconcepts.nim | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/concepts/templatesinconcepts.nim b/tests/concepts/templatesinconcepts.nim new file mode 100644 index 000000000..292b97ea6 --- /dev/null +++ b/tests/concepts/templatesinconcepts.nim @@ -0,0 +1,56 @@ +import typetraits + +template typeLen(x): int = x.type.name.len + +template bunchOfChecks(x) = + x.typeLen > 3 + x != 10 is bool + +template stmtListExprTmpl(x: untyped): untyped = + x is int + x + +type + Obj = object + x: int + + Gen[T] = object + x: T + + Eq = concept x, y + (x == y) is bool + + NotEq = concept x, y + (x != y) is bool + + ConceptUsingTemplate1 = concept x + echo x + sizeof(x) is int + bunchOfChecks x + + ConceptUsingTemplate2 = concept x + stmtListExprTmpl x + +template ok(x) = + static: assert(x) + +template no(x) = + static: assert(not(x)) + +ok int is Eq +ok int is NotEq +ok string is Eq +ok string is NotEq +ok Obj is Eq +ok Obj is NotEq +ok Gen[string] is Eq +ok Gen[int] is NotEq + +no int is ConceptUsingTemplate1 +ok float is ConceptUsingTemplate1 +no string is ConceptUsingTemplate1 + +ok int is ConceptUsingTemplate2 +no float is ConceptUsingTemplate2 +no string is ConceptUsingTemplate2 + |