Listing.join and List.join do not call toString override on elements #272

Open
opened 2025-12-30 01:23:04 +01:00 by adam · 1 comment
Owner

Originally created by @HT154 on GitHub (Jan 31, 2025).

Given input

class Thing {
  a: Int
  b: Int
  function toString(): String = "\(a):\(b)"
}

local thingListing = new Listing<Thing> {
  new { a = 10; b = 20 }
  new { a = 30; b = 40 }
}

local thingList = thingListing.toList()

resultListing = thingListing.join("\n")
resultList = thingList.join("\n")

The expected output is

resultListing = """
  10:20
  30:30
  """
resultList = """
  10:20
  30:30
  """

The actual output is

resultListing = """
  new Thing { a = 10; b = 20 }
  new Thing { a = 30; b = 40 }
  """
resultList = """
  new Thing { a = 10; b = 20 }
  new Thing { a = 30; b = 40 }
  """

Other instances where Pkl can convert arbitrary values to String (i.e. string interpolation) correctly call the value's toString() method.

Originally created by @HT154 on GitHub (Jan 31, 2025). Given input ```pkl class Thing { a: Int b: Int function toString(): String = "\(a):\(b)" } local thingListing = new Listing<Thing> { new { a = 10; b = 20 } new { a = 30; b = 40 } } local thingList = thingListing.toList() resultListing = thingListing.join("\n") resultList = thingList.join("\n") ``` The expected output is ```pkl resultListing = """ 10:20 30:30 """ resultList = """ 10:20 30:30 """ ``` The actual output is ```pkl resultListing = """ new Thing { a = 10; b = 20 } new Thing { a = 30; b = 40 } """ resultList = """ new Thing { a = 10; b = 20 } new Thing { a = 30; b = 40 } """ ``` Other instances where Pkl can convert arbitrary values to `String` (i.e. string interpolation) correctly call the value's `toString()` method.
Author
Owner

@bioball commented on GitHub (Feb 3, 2025):

This seems like a bug to me.

This would also be a breaking change if fixed.

@bioball commented on GitHub (Feb 3, 2025): This seems like a bug to me. This would also be a breaking change if fixed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#272