Skip to content

sourcecode.Text applied to infix operator works unintuitively. #72

Description

@pocorall
class MyBuilder {
  val builder = new StringBuilder

  def add[T](txt: sourcecode.Text[T]): MyBuilder = {
    builder append txt.source
    this
  }

  def +[T](txt: sourcecode.Text[T]): MyBuilder = {
    builder append txt.source
    this
  }
}

val hello = 3
val world = "hi!"

new MyBuilder().add(hello).add(world).builder.toString() // equals to "helloworld"
(new MyBuilder() + hello + world).builder.toString() // equals to "hello + worldworld"

I hope that .add(hello).add(world) and + hello + world make the same result.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions