summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/system/repr_v2.nim8
-rw-r--r--tests/arc/trepr.nim30
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/system/repr_v2.nim b/lib/system/repr_v2.nim
index fa04ba5a9..407a06844 100644
--- a/lib/system/repr_v2.nim
+++ b/lib/system/repr_v2.nim
@@ -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
diff --git a/tests/arc/trepr.nim b/tests/arc/trepr.nim
index 7a92112ed..e24c112ac 100644
--- a/tests/arc/trepr.nim
+++ b/tests/arc/trepr.nim
@@ -4,6 +4,12 @@ discard """
 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