File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -4008,7 +4008,14 @@ object Parsers {
4008
4008
val tpt = typedOpt()
4009
4009
val rhs =
4010
4010
if tpt.isEmpty || in.token == EQUALS then
4011
- accept(EQUALS )
4011
+ if tpt.isEmpty && in.token != EQUALS then
4012
+ lhs match
4013
+ case Ident (name) :: Nil if name.endsWith(" :" ) =>
4014
+ val help = i " ; identifier ends in colon, did you mean ` ${name.toSimpleName.dropRight(1 )}`: in backticks? "
4015
+ syntaxErrorOrIncomplete(ExpectedTokenButFound (EQUALS , in.token, suffix = help))
4016
+ case _ => accept(EQUALS )
4017
+ else
4018
+ accept(EQUALS )
4012
4019
val rhsOffset = in.offset
4013
4020
subExpr() match
4014
4021
case rhs0 @ Ident (name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
Original file line number Diff line number Diff line change
1
+
1
2
import _root_ .scala .StringContext // ok
2
3
3
4
class Test :
Original file line number Diff line number Diff line change
1
+ -- [E040] Syntax Error: tests/neg/i18020b.scala:2:17 -------------------------------------------------------------------
2
+ 2 |class i18020(a_: Int): // error
3
+ | ^^^
4
+ | ':' expected, but identifier found
5
+ -- [E040] Syntax Error: tests/neg/i18020b.scala:3:12 -------------------------------------------------------------------
6
+ 3 | def f(b_: Int) = 42 // error
7
+ | ^^^
8
+ | ':' expected, but identifier found
9
+ -- [E040] Syntax Error: tests/neg/i18020b.scala:4:10 -------------------------------------------------------------------
10
+ 4 | def g_: Int = 27 // error
11
+ | ^^^
12
+ | '=' expected, but identifier found
13
+ -- [E040] Syntax Error: tests/neg/i18020b.scala:6:12 -------------------------------------------------------------------
14
+ 6 | val x_: Int = 1 // error
15
+ | ^^^
16
+ | '=' expected, but identifier found; identifier ends in colon, did you mean `x_`: in backticks?
17
+ -- [E040] Syntax Error: tests/neg/i18020b.scala:7:12 -------------------------------------------------------------------
18
+ 7 | val y_: Int = 2 // error
19
+ | ^^^
20
+ | '=' expected, but identifier found; identifier ends in colon, did you mean `y_`: in backticks?
21
+ -- [E006] Not Found Error: tests/neg/i18020b.scala:8:4 -----------------------------------------------------------------
22
+ 8 | x_ + y_ // error
23
+ | ^^
24
+ | Not found: x_ - did you mean x_:?
25
+ |
26
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ // problems with colon fusion, a harder challenge than cold fusion
2
+ class i18020 (a_ : Int ): // error
3
+ def f (b_ : Int ) = 42 // error
4
+ def g_: Int = 27 // error
5
+ def k =
6
+ val x_: Int = 1 // error
7
+ val y_: Int = 2 // error
8
+ x_ + y_ // error
You can’t perform that action at this time.
0 commit comments