Skip to content

Commit 2d60032

Browse files
committed
Deprecate empty colonized template bodies
End markers should be strictly optional, in the sense that source must compile correctly if they are deleted. Emitting a deprecation warning for `class C:` followed immediately by `end C` is annoying enough to encourage the user to quickly add a statement in their next edit.
1 parent c6281f1 commit 2d60032

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,9 @@ object Parsers {
12621262
def possibleTemplateStart(isNew: Boolean = false): Unit =
12631263
in.observeColonEOL()
12641264
if in.token == COLONEOL then
1265-
if in.lookahead.token == END then in.token = NEWLINE
1265+
if in.lookahead.token == END then
1266+
deprecationWarning("expected indented definitions after colon, found an empty template with mandatory end marker")
1267+
in.token = NEWLINE
12661268
else
12671269
in.nextToken()
12681270
if in.token != INDENT && in.token != LBRACE then
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
// empty colonized template body is deprecated
3+
4+
class C: // error
5+
end C
6+
7+
trait T: // error
8+
end T
9+
10+
// sample trivial non-empty body
11+
12+
class D:
13+
this: D =>
14+
end D
15+
16+
trait U:
17+
this: U =>
18+
end U

0 commit comments

Comments
 (0)