Skip to content

given declarations with & do not compile as expected #22677

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

Closed
amaalali opened this issue Feb 27, 2025 · 5 comments
Closed

given declarations with & do not compile as expected #22677

amaalali opened this issue Feb 27, 2025 · 5 comments
Labels
area:implicits related to implicits itype:bug stat:fixed in next The issue was fixed in Next and only still applies to LTS. stat:wontfix

Comments

@amaalali
Copy link

Compiler version

3.3.5

Minimized code

trait A:
  def a: Unit

trait B:
  def b: Unit

class ABImpl extends A, B:
  def a: Unit = println("a")
  def b: Unit = println("b")

// Compiles when a type alias is used
type AB = A & B
given namedGivenWithTypeAlias: AB = ABImpl()
given AB = ABImpl()

// Compiles with parentheses
given namedGivenWithParentheses: (A & B) = ABImpl()
given (A & B) = ABImpl()

// Does not compile when & is used inline
given namedGivenInline: A & B = ABImpl()
given A & B = ABImpl()

Output

[error] ./test.scala:24:27
[error] 'with' expected, but identifier found
[error] given namedGivenInline: A & B = ABImpl()
[error]                           ^
[error] ./test.scala:25:9
[error] 'with' expected, but identifier found
[error] given A & B = ABImpl()
[error]         ^
Error compiling project (Scala 3.3.5, JVM (21))

Expectation

given namedGivenInline: A & B = ABImpl() and given A & B = ABImpl() should compile as valid given declarations.

@amaalali amaalali added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 27, 2025
@amaalali
Copy link
Author

amaalali commented Feb 27, 2025

This doesn't seem to be an issue in 3.6.3

Minimized code

trait A:
  def a: Unit

trait B:
  def b: Unit

class ABImpl extends A, B:
  def a: Unit = println("a")
  def b: Unit = println("b")

// Compiles when a type alias is used
type AB = A & B
given namedGivenWithTypeAlias: AB = ABImpl()
given AB = ABImpl()


// Compiles with parentheses
object A:
  given namedGivenWithParentheses: (A & B) = ABImpl()
object B:
  given (A & B) = ABImpl()

// Does not compile when & is used inline
object C:
  given namedGivenInline: A & B = ABImpl()

object D:
  given A & B = ABImpl()

(modification of the original snippet was required as 3.6.3 returns a different error)

@WojciechMazur
Copy link
Contributor

The fix, available since 3.6, was introduced probably in #21208 and #21668, both of which are not backportable to Scala 3.3 LTS.
To fix it in the LTS we'd need to carefully adopt some of the changes introduced in these 2 PR without introducing any changes related to new givens syntax.

@SethTisue SethTisue changed the title given declarations with & do no compile as expected given declarations with & do not compile as expected Mar 1, 2025
@Gedochao Gedochao added area:implicits related to implicits stat:fixed in next The issue was fixed in Next and only still applies to LTS. labels Mar 3, 2025
@Gedochao
Copy link
Contributor

Gedochao commented Mar 3, 2025

@WojciechMazur @tgodzik
Backporting those PRs to the LTS was rejected previously.
Is this a wontfix for the LTS, or should we re-attempt this?

@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Mar 3, 2025
@WojciechMazur
Copy link
Contributor

I'd say that's a won't fix.
The general policy for LTS was that we focus on backporting changes from Next, instead of actively developing the LTS branch. If the fix is possible, but does require a dedicated work based on existing changes (like in this case) we'd welcome an external contributors willing to create a PR that might be merged into LTS if it does not couse any new regressions. I'm afraid we don't have enough resources to assign dedicated developer to work on this right now.
It might become a topic for compiler spree

@Gedochao
Copy link
Contributor

Gedochao commented Mar 3, 2025

Alright. I'm closing it for now then.

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug stat:fixed in next The issue was fixed in Next and only still applies to LTS. stat:wontfix
Projects
None yet
Development

No branches or pull requests

3 participants