Skip to content

Commit 293f18c

Browse files
committed
Align treatment of colon in template bodies and arguments
1 parent b1a6867 commit 293f18c

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ object Scanners {
648648

649649
def observeColonEOL(inTemplate: Boolean): Unit =
650650
val enabled =
651-
if inTemplate then token == COLONop || token == COLONfollow
652-
else token == COLONfollow && fewerBracesEnabled
651+
if token == COLONop && inTemplate then
652+
report.deprecationWarning(em"`:` after symbolic operator is deprecated; use backticks around operator instead", sourcePos(offset))
653+
true
654+
else token == COLONfollow && (inTemplate || fewerBracesEnabled)
653655
if enabled then
654656
lookAhead()
655657
val atEOL = isAfterLineEnd || token == EOF

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ object Tokens extends TokensCommon {
283283

284284
final val endMarkerTokens = identifierTokens | BitSet(IF, WHILE, FOR, MATCH, TRY, NEW, THROW, GIVEN, VAL, THIS)
285285

286-
final val colonEOLPredecessors = BitSet(RPAREN, RBRACKET, BACKQUOTED_IDENT, THIS, SUPER)
286+
final val colonEOLPredecessors = BitSet(RPAREN, RBRACKET, BACKQUOTED_IDENT, THIS, SUPER, NEW)
287287

288288
final val closingParens = BitSet(RPAREN, RBRACKET, RBRACE)
289289

docs/_docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ notation `:<<< ts >>>` indicates a token sequence `ts` that is either enclosed i
9999
a `colon` token.
100100

101101
A `colon` token reads as the standard colon "`:`" but is generated instead of it where `colon` is legal according to the context free syntax, but only if the previous token
102-
is an alphanumeric identifier, a backticked identifier, or one of the tokens `this`, `super`, "`)`", and "`]`".
102+
is an alphanumeric identifier, a backticked identifier, or one of the tokens `this`, `super`, `new`, "`)`", and "`]`".
103103

104104
```
105105
colon ::= ':' -- with side conditions explained above

tests/run/LazyLists.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ package xcollections:
4646
val empty: LazyList[Nothing] = new:
4747
protected def force(): LazyList[Nothing] = this
4848

49-
object #:: :
49+
object `#::`:
5050
def unapply[T](xs: LazyList[T]): Option[(T, LazyList[T])] =
5151
if xs.isEmpty then None
5252
else Some((xs.head, xs.tail))

0 commit comments

Comments
 (0)