File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -4008,7 +4008,14 @@ object Parsers {
40084008 val tpt = typedOpt()
40094009 val rhs =
40104010 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 )
40124019 val rhsOffset = in.offset
40134020 subExpr() match
40144021 case rhs0 @ Ident (name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
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