Skip to content

Conversation

@soronpo
Copy link
Contributor

@soronpo soronpo commented Aug 25, 2025

No description provided.

…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.
Copy link
Member

@bishabosha bishabosha Aug 26, 2025

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **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 foo

Copy link
Contributor Author

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

@prolativ
Copy link
Contributor

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 foo

And similarly

class CurriedFoo(bar: String):
  def apply(baz: String) = ???
  
def foo(bar: String) = CurriedFoo(bar)

foo("abc"):
  "xyz"
end foo

@soronpo
Copy link
Contributor Author

soronpo commented Sep 25, 2025

E.g. should this work?

Yes. Nothing explicitly is speced to prevent such application.

@bracevac bracevac changed the title SIP-NN - End markers for method blocks and anonymous classes SIP-77 - End markers for method blocks and anonymous classes Sep 26, 2025
Copy link
Contributor

@odersky odersky left a 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 new

And so does this:

val foo = new Foo:
  // do something
  // overrides, vals, defs...
end foo

I 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 foo

is this supposed to work? It would be the first instance where we allow multiple ends on the same indentation level.

@bjornregnell
Copy link

bjornregnell commented Oct 24, 2025

I don't think end on the same indentation level should work as it does not give a strong visual clue on the nesting order.

@soronpo
Copy link
Contributor Author

soronpo commented Oct 24, 2025

As discussed, I opened a ticket for end new not working under all conditions: scala/scala3#24250 and I'm removing anonymous class cases from this SIP.

@soronpo soronpo changed the title SIP-77 - End markers for method blocks and anonymous classes SIP-77 - End Markers for Method Blocks Oct 24, 2025
Comment on lines +38 to +40
foo(42):
// do something
// more nested blocks...
Copy link
Contributor

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

@soronpo
Copy link
Contributor Author

soronpo commented Oct 24, 2025

Implementation scala/scala3#24251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants