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.
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.
| - **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.
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. |
odersky
left a comment
There was a problem hiding this comment.
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.
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 |
|
Please note that the SIP template has changed:
Thanks! |
No description provided.