Skip to content

Commit

Permalink
more test cases for generic object impl AST (nim-lang#22077)
Browse files Browse the repository at this point in the history
closes nim-lang#9899, closes nim-lang#14708, refs nim-lang#21017

temp
  • Loading branch information
metagn authored and jmgomez committed Jun 11, 2023
1 parent 5813087 commit 06bf5ed
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
2 changes: 0 additions & 2 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
## This module implements semantic checking for calls.
# included from sem.nim

from std/algorithm import sort


proc sameMethodDispatcher(a, b: PSym): bool =
result = false
Expand Down
3 changes: 2 additions & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,10 @@ proc getDependency(n: PNode): string =
case objNod[1][0].kind:
of nkIdent: objNod[1][0]
of nkBracketExpr: objNod[1][0][0]
of nkDotExpr: objNod[1][0][1]
else:
nil
assert ident != nil, "Expected nkIdent or nkBracketExpr got: " & $objNod[1][0].kind
assert ident != nil, "Expected nkIdent, nkDotExpr or nkBracketExpr got: " & $objNod[1][0].kind
ident.ident.s

proc dfs(current: PNode, nodes: seq[PNode], indexMap: Table[string, int], visited: var seq[string], result: var seq[PNode]) =
Expand Down
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 06bf5ed

Please sign in to comment.