more test cases for generic object impl AST (#22077)

closes #9899, closes #14708, refs #21017
This commit is contained in:
metagn
2023-06-11 20:20:17 +03:00
committed by GitHub
parent 5139a2ec37
commit 7b1c448744
2 changed files with 49 additions and 21 deletions

View File

@@ -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()

View File

@@ -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))