diff options
author | metagn <metagngn@gmail.com> | 2023-06-11 20:20:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 19:20:17 +0200 |
commit | 7b1c448744f9b29a41d205f102fb2b4e7f735d88 (patch) | |
tree | 94c31df65105abb46b2f880b891983d0fafffc77 /tests/generics | |
parent | 5139a2ec37960f7d16a284369e0497efa331cd87 (diff) | |
download | Nim-7b1c448744f9b29a41d205f102fb2b4e7f735d88.tar.gz |
more test cases for generic object impl AST (#22077)
closes #9899, closes #14708, refs #21017
Diffstat (limited to 'tests/generics')
-rw-r--r-- | tests/generics/t16639.nim | 21 | ||||
-rw-r--r-- | tests/generics/timpl_ast.nim | 49 |
2 files changed, 49 insertions, 21 deletions
diff --git a/tests/generics/t16639.nim b/tests/generics/t16639.nim deleted file mode 100644 index fc00dfc34..000000000 --- a/tests/generics/t16639.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - action: compile -""" - -type Foo[T] = object - when true: - x: float - -type Bar = object - when true: - x: float - -import std/macros -import std/assertions - -macro test() = - let a = getImpl(bindSym"Foo")[^1] - let b = getImpl(bindSym"Bar")[^1] - doAssert treeRepr(a) == treeRepr(b) - -test() diff --git a/tests/generics/timpl_ast.nim b/tests/generics/timpl_ast.nim new file mode 100644 index 000000000..69a59e24d --- /dev/null +++ b/tests/generics/timpl_ast.nim @@ -0,0 +1,49 @@ +discard """ + action: compile +""" + +import std/macros +import std/assertions + +block: # issue #16639 + type Foo[T] = object + when true: + x: float + + type Bar = object + when true: + x: float + + macro test() = + let a = getImpl(bindSym"Foo")[^1] + let b = getImpl(bindSym"Bar")[^1] + doAssert treeRepr(a) == treeRepr(b) + + test() + +import strutils + +block: # issues #9899, ##14708 + macro implRepr(a: typed): string = + result = newLit(repr(a.getImpl)) + + type + Option[T] = object + when false: discard # issue #14708 + when false: x: int + when T is (ref | ptr): + val: T + else: + val: T + has: bool + + static: # check information is retained + let r = implRepr(Option) + doAssert "when T is" in r + doAssert r.count("val: T") == 2 + doAssert "has: bool" in r + + block: # try to compile the output + macro parse(s: static string) = + result = parseStmt(s) + parse("type " & implRepr(Option)) |