mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 14:32:53 +00:00
more test cases for generic object impl AST (#22077)
closes #9899, closes #14708, refs #21017
This commit is contained in:
@@ -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()
|
||||
49
tests/generics/timpl_ast.nim
Normal file
49
tests/generics/timpl_ast.nim
Normal 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))
|
||||
Reference in New Issue
Block a user