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

Overloaded extension method usage does not compile if the body of its callback argument is wrapped in braces #18645

Closed
raquo opened this issue Oct 4, 2023 · 0 comments · Fixed by #19651
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@raquo
Copy link
Contributor

raquo commented Oct 4, 2023

Compiler version

Problem observed on 3.3.1. The problem started with 3.1.2, whereas 3.1.1 works fine. (according to scastie)

Minimized code

trait Printable {
  def pprint(v: () => String): Unit = {
    println(v())
  }
}

extension (ctx: Printable)
  def pprint(f: () => Int): Unit = {
    ctx.pprint(() => f().toString)
  }

val x = new Printable {}

def test =
  x.pprint(() => "hello")       // ok
  x.pprint(() => { "hello" })   // ok
  x.pprint(() => 123)           // ok
  x.pprint(() => ( 123 ))       // ok
  x.pprint(() => { 123 })       // FAIL

https://scastie.scala-lang.org/ShYSWt7NSnusCJKuCu8OOw

Output

In Scala 3.3.1 and as early as 3.1.2, this line: x.pprint(() => { 123 }) causes compiler error:

Found:    (123 : Int)
Required: String

Whereas in Scala 3.1.1, that line compiles fine.

Expectation

x.pprint(() => { 123 }) should compile, consistently with other similar usages shown in the code snippet.

@raquo raquo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 4, 2023
@bishabosha bishabosha added regression This worked in a previous version but doesn't anymore area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2023
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants