You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When dealing with `apply` methods, the end marker follows the explicit method name used in the call:
48
+
49
+
**Explicit `apply` calls**: Use `end apply` when the method is called explicitly with `.apply`.
50
+
51
+
```scala
52
+
objectFoo:
53
+
defapply(block: =>Unit):Unit= ()
54
+
55
+
Foo.apply:
56
+
// do something
57
+
endapply
58
+
```
59
+
60
+
**Implicit `apply` calls**: Use the name of the object/class instance that owns the `apply` method when it's called implicitly.
61
+
62
+
```scala
63
+
objectFoo:
64
+
defapply(block: =>Unit):Unit= ()
65
+
66
+
Foo:
67
+
// do something
68
+
endFoo
69
+
```
70
+
71
+
```scala
72
+
classFoo:
73
+
defapply(block: =>Unit):Unit= ()
74
+
75
+
valfoo=newFoo
76
+
foo:
77
+
// do something
78
+
endfoo
79
+
```
80
+
81
+
This rule ensures that the end marker always corresponds to the syntactically visible method name, making the code self-documenting and consistent with the principle that end markers should match the surface syntax.
82
+
83
+
## How to Enable
84
+
85
+
To use end markers for method blocks, you need to enable the experimental feature:
Alternatively, you can enable it globally with the compiler flag:
92
+
93
+
```
94
+
-language:experimental.methodBlockEndMarkers
95
+
```
96
+
97
+
## When to Use
98
+
99
+
Method block end markers are particularly useful when:
100
+
101
+
- You have deeply nested method calls with colon syntax
102
+
- You want to improve code readability by explicitly marking block boundaries
103
+
- You're working with DSLs or testing frameworks that use method blocks extensively
104
+
105
+
## Limitations
106
+
107
+
- End markers only work with method applications that use colon syntax (braceless arguments)
108
+
- The end marker name must exactly match the method name
109
+
- This feature is experimental and may undergo API changes in future releases
110
+
111
+
## Error Cases
112
+
113
+
The compiler will report errors for misaligned end markers:
114
+
115
+
```scala
116
+
test("my test"):
117
+
valx=1
118
+
assert(x >0)
119
+
endwrong// Error: misaligned end marker
120
+
```
121
+
122
+
## Interaction with Other Features
123
+
124
+
This feature works alongside the existing `fewerBraces` feature and follows the same syntactic patterns. It extends the end marker functionality to method application blocks.
0 commit comments