Skip to content

Commit

Permalink
Fix nim-lang#14270 and add testcases (nim-lang#14276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber authored and EchoPouet committed Jun 13, 2020
1 parent a06a338 commit 306f10d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/system/repr_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ proc repr*[T: tuple|object](x: T): string =

proc repr*[T](x: ref T | ptr T): string =
if isNil(x): return "nil"
result = $typeof(x)
reprObject(result, x[])
when T is object:
result = $typeof(x)
reprObject(result, x[])
else:
result = when typeof(x) is ref: "ref " else: "ptr "
result.add repr(x[])

proc collectionToRepr[T](x: T, prefix, separator, suffix: string): string =
result = prefix
Expand Down
30 changes: 30 additions & 0 deletions tests/arc/trepr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ discard """
nimout: '''(a: true, n: doAssert)
Table[system.string, trepr.MyType](data: @[], counter: 0)
nil
'''
output: '''
nil
2
Obj(member: ref @[hello])
ref (member: ref @[hello])
'''
"""
import tables
Expand Down Expand Up @@ -32,3 +38,27 @@ macro dumpSym(a: typed) =

dumpSym(doAssert)

# bug 13731

import os
var a: File
echo repr a

# bug 13872

echo repr(2'u16)

# bug 14270

type
Obj = ref object
member: ref seq[string]

var c = Obj(member: new seq[string])
c.member[] = @["hello"]
echo c.repr

var c2 = new tuple[member: ref seq[string]]
c2.member = new seq[string]
c2.member[] = @["hello"]
echo c2.repr

0 comments on commit 306f10d

Please sign in to comment.