-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add a specific error message for local final defs #20557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main thing is to remove or motivate the restriction why GIVEN is excluded. Otherwise LGTM.
tests/neg/17579.check
Outdated
-- [E088] Syntax Error: tests/neg/17579.scala:6:10 --------------------------------------------------------------------- | ||
6 | final private val v3 = 42 // error | ||
| ^^^^^^^ | ||
| Expected start of definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a different error message here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why: since private
is also not a local modifier token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we could generalize the solution. We could always parse all tokens and then flag those that are not legal at this point. But this could be another PR.
We thought we should not emit an error in this case, as And there is an existing warning for trait Foo:
def foo: Int
@main def f() =
final given Foo with
def foo = 42 ➜ ~/scala-snippets-5 scala-cli -Xprint:typer final_given.scala
Compiling project (Scala 3.4.1, JVM (17))
[warn] ./final_given.scala:7:3
[warn] Modifier final is redundant for this definition
[warn] final given Foo with
[warn] ^^^^^
[[syntax trees at end of typer]] // /Users/mbovel/scala-snippets-5/final_given.scala
package final_given {
trait Foo() extends Object {
def foo: Int
}
final lazy module val final_given$package: final_given.final_given$package =
new final_given.final_given$package()
final module class final_given$package() extends Object() {
this: final_given.final_given$package.type =>
@main def f(): Unit =
{
final lazy module given val given_Foo: given_Foo = new given_Foo()
final module class given_Foo() extends Object(), final_given.Foo {
this: given_Foo.type =>
def foo: Int = 42
}
... Does that make sense? Should I had a comment to explain this where we through the error? |
I rebased on main, and added comments in the parser and in the test case. |
Co-Authored-By: Eugene Flesselle <eugene@flesselle.net> Co-Authored-By: anna herlihy <herlihyap@gmail.com> Co-Authored-By: Oliver Bračevac <bracevac@users.noreply.github.com>
Fixes #17579.