Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HT154 opened this issue Jan 31, 2025 · 1 comment
Open

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

HT154 opened this issue Jan 31, 2025 · 1 comment

Comments

@HT154
Copy link
Contributor

HT154 commented 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.

@bioball
Copy link
Contributor

bioball commented Feb 3, 2025

This seems like a bug to me.

This would also be a breaking change if fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants