pkl icon indicating copy to clipboard operation
pkl copied to clipboard

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

Open HT154 opened this issue 11 months ago • 1 comments

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.

HT154 avatar Jan 31 '25 21:01 HT154

This seems like a bug to me.

This would also be a breaking change if fixed.

bioball avatar Feb 03 '25 19:02 bioball