fix: guard against non-string toString in IO.print and IO.write
Add writeObject_ helper that checks if obj.toString returns a String before writing it, falling back to "[invalid toString]" otherwise. Update print, write, and printList_ to use the new helper instead of calling toString directly. Include test cases for both IO.print and IO.write with a class whose toString returns an integer.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
class BadToString {
|
||||
toString { 3 }
|
||||
}
|
||||
|
||||
IO.print(new BadToString) // expect: [invalid toString]
|
||||
@@ -0,0 +1,6 @@
|
||||
class BadToString {
|
||||
toString { 3 }
|
||||
}
|
||||
|
||||
IO.write(new BadToString) // expect: [invalid toString]
|
||||
IO.print
|
||||
Reference in New Issue
Block a user