Skip to content

Commit

Permalink
more test cases for generic object impl AST (#22077)
Browse files Browse the repository at this point in the history
closes #9899, closes #14708, refs #21017
  • Loading branch information
metagn authored Jun 11, 2023
1 parent 5139a2e commit 7b1c448
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
21 changes: 0 additions & 21 deletions tests/generics/t16639.nim

This file was deleted.

49 changes: 49 additions & 0 deletions tests/generics/timpl_ast.nim
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 7b1c448

Please sign in to comment.