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

Regression in parser for refined givens #21958

Open
WojciechMazur opened this issue Nov 15, 2024 · 3 comments
Open

Regression in parser for refined givens #21958

WojciechMazur opened this issue Nov 15, 2024 · 3 comments
Assignees
Labels
area:parser itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Nov 15, 2024

Regression found during work on fix for other parser regression in #21957

Compiler version

Last good release: 3.5.0-RC1-bin-20240506-1cdf99f-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240508-b10d64e-NIGHTLY

Bisect points it could have been introduced by either ea3c688 or 5189e68

Minimized code

trait Foo[T]:
  def foo(v: T): Unit

given myFooOfUnit: Foo[Unit]{ type X = Int } = new Foo[Unit] {
    type X = Int
    def foo(v: Unit): Unit = ???
  }

@main def Test = 
  summon[Foo[Unit]{type X = Int}]

Output

[error] ./tmp.scala:5:29
[error] 'with' expected, but '{' found
[error] given myFooOfUnit: Foo[Unit]{ type X = Int } = new Foo[Unit] {
[error]                             ^
[error] ./tmp.scala:11:34
[error] '}' expected, but eof found
[error]   summon[Foo[Unit]{type X = Int}]
[error]                     

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:parser regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 15, 2024
@Gedochao
Copy link
Contributor

cc @odersky @KacperFKorban

@KacperFKorban
Copy link
Member

This is a similar issue to what I discussed with @EugeneFlesselle recently (but I haven't filed a discussion for it yet).
In the following code snippet, the { type X = String } part is considered the implementation of the given, not the refinement.

trait Bar:
  type Self
  type X

given w: Int is Bar { type X = String }

But this is probably impossible to disambiguate when parsing in this example.

@odersky odersky self-assigned this Nov 17, 2024
@odersky
Copy link
Contributor

odersky commented Nov 17, 2024

The syntax always specified that in an alias given the implemented type must be an AnnotType.

For instance, in the LTS syntax.md at https://github.com/scala/scala3/blob/lts-3.3/docs/_docs/reference/syntax.md:

GivenDef          ::=  [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)

So I believe this was a mistake that got fixed in 3.5. The workaround is simple: Put the refined type in parens.

given myFooOfUnit: (Foo[Unit]{ type X = Int }) = ...

I think we can leave this as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:parser itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

4 participants