Skip to content

By-name arguments do not behave as expected with right-associative operators #2808

Closed
@smarter

Description

@smarter

This is the same bug as scala/bug#1980:

class C {
  def m2_:(f: => Int) = ()
}

object Test {
  def foo() = { println("foo") ; 5 }

  def main(args: Array[String]): Unit = {
    val c = new C
    foo() m2_: c
  }
}

This should print nothing but ends up printing foo because we desugar:

foo() m2_: c

into:

val $1$: Int = Test.foo()
c.m2_:($1$)

In scalac this was basically unfixable because this desugaring is done during parsing, but in dotty we should have the type of m2_: during desugaring which tells us that its argument is by-name and thus we could simply do:

lazy val $1$: Int = Test.foo()
c.m2_:($1$)

Whether or not this is fixed might influence the design of the collection strawman: scala/collection-strawman#127

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions