-
Notifications
You must be signed in to change notification settings - Fork 29
SIP-77 - End Markers for Method Blocks #116
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
base: main
Are you sure you want to change the base?
Conversation
…ous classes to enhance readability and tooling support in Scala 3's braceless syntax.
|
|
||
| - Binary and TASTy: No impact. End markers are purely syntactic sugar for braceless blocks and do not affect emitted bytecode or TASTy semantics. | ||
| - Source: Largely backward compatible. The only change is accepting additional `end <id>` and `end new` tokens where previously only a dedentation closed the block. Name-checked markers that do not match will report errors as they do today for definition end markers. | ||
| - Tooling: Formatters and IDEs may optionally insert or display these markers; existing code without markers remains valid. |
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.
Couple of examples:
- Metals (via SemanticDB) - references to method symbol to include the new end marker
- Presentation Compiler? if that also reports symbol occurrences in source files
| end apply | ||
| ``` | ||
|
|
||
| - **Implicit `apply` calls**: Use the name of the object/class that owns the `apply` method when it's called implicitly. |
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.
| - **Implicit `apply` calls**: Use the name of the object/class that owns the `apply` method when it's called implicitly. | |
| - **Implicit `apply` calls**: Use the name of the object/class instance that owns the `apply` method when it's called implicitly. |
I believe this was intended for cases like
class Foo:
def apply(block: => Unit): Unit = ()
val foo = new Foo
foo:
// do something
end fooThere 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.
Yes, I'll add this example
|
What about curried methods as they were not mentioned explicitly here? E.g. should this work? def foo(bar: String)(baz: String) = ???
foo("abc"):
"xyz"
end fooAnd similarly class CurriedFoo(bar: String):
def apply(baz: String) = ???
def foo(bar: String) = CurriedFoo(bar)
foo("abc"):
"xyz"
end foo |
Yes. Nothing explicitly is speced to prevent such application. |
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.
End markers for method calls fill an important hole.
End markers for new are in fact already implemented. This works
val foo =
new Foo:
// do something
// overrides, vals, defs...
end newAnd so does this:
val foo = new Foo:
// do something
// overrides, vals, defs...
end fooI don't think we need another case were we also allow end new in the second case.
I am not sure about disambiguation:
def foo = bar:
...
end bar
end foois this supposed to work? It would be the first instance where we allow multiple ends on the same indentation level.
|
I don't think |
|
As discussed, I opened a ticket for |
| foo(42): | ||
| // do something | ||
| // more nested blocks... |
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 think all the examples we give (except for some counterexamples) should be valid scala code (currently or after the SIP would become a part of the language). This snippet below is not one, because fewer-braces syntax requires non-empy code blocks (and comments don't count as code in this sence).
The same applies for some other examples below
|
Implementation scala/scala3#24251 |
No description provided.