Unexpected success in string concatenation

54 views
Skip to first unread message

Richard Sargent

unread,
Sep 6, 2019, 1:28:33 PM9/6/19
to VA Smalltalk
I was reviewing some code in the GBS tester when I came across the equivalent of
'Test failed because ', Object new

I was surprised that worked, so I looked into it. I'm posting this so that others will be aware of this potentially unexpected behaviour.


It succeeds since the variable size of an arbitrary object is zero. The concatenation method doesn't care that the receiver is bytes and the argument is objects. There are zero of them to add to the concatenation, so it quietly works.


I do think the behaviour is correct.

Wayne Johnston

unread,
Sep 9, 2019, 3:55:12 PM9/9/19
to VA Smalltalk
Cute.  These also work:

'Test failed because ', 5.
'Test failed because ', nil.
'Test failed because ', [self halt]. 
Reply all
Reply to author
Forward
0 new messages