mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user