parent
de27910ab7
commit
120ea906fb
2 changed files with 36 additions and 2 deletions
|
|
@ -106,8 +106,12 @@ proc repr*[T: tuple|object](x: T): string =
|
||||||
|
|
||||||
proc repr*[T](x: ref T | ptr T): string =
|
proc repr*[T](x: ref T | ptr T): string =
|
||||||
if isNil(x): return "nil"
|
if isNil(x): return "nil"
|
||||||
|
when T is object:
|
||||||
result = $typeof(x)
|
result = $typeof(x)
|
||||||
reprObject(result, 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 =
|
proc collectionToRepr[T](x: T, prefix, separator, suffix: string): string =
|
||||||
result = prefix
|
result = prefix
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@ discard """
|
||||||
nimout: '''(a: true, n: doAssert)
|
nimout: '''(a: true, n: doAssert)
|
||||||
Table[system.string, trepr.MyType](data: @[], counter: 0)
|
Table[system.string, trepr.MyType](data: @[], counter: 0)
|
||||||
nil
|
nil
|
||||||
|
'''
|
||||||
|
output: '''
|
||||||
|
nil
|
||||||
|
2
|
||||||
|
Obj(member: ref @[hello])
|
||||||
|
ref (member: ref @[hello])
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
import tables
|
import tables
|
||||||
|
|
@ -32,3 +38,27 @@ macro dumpSym(a: typed) =
|
||||||
|
|
||||||
dumpSym(doAssert)
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue