Skip to content

Commit 9f3005c

Browse files
authored
Merge pull request #1630 from m-sp/master
Add error message Parsers.scala:1620 missing type keyword
2 parents 167a885 + ba7f011 commit 9f3005c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ object Parsers {
16231623
val mod = atPos(in.skipToken()) { Mod.Type() }
16241624
(mods | Param | ParamAccessor).withAddedMod(mod)
16251625
} else {
1626-
if (mods.hasFlags) syntaxError("`type' expected")
1626+
if (mods.hasFlags) syntaxError(TypeParamsTypeExpected(mods, ident()))
16271627
mods | Param | PrivateLocal
16281628
}
16291629
}

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,5 +677,18 @@ object messages {
677677
|
678678
|$fixedVarInAlternative""".stripMargin
679679
}
680+
}
681+
682+
case class TypeParamsTypeExpected(mods: Modifiers, identifier: TermName)(implicit ctx: Context) extends Message(24) {
683+
val kind = "Syntax"
684+
685+
val msg = hl"""Expected ${"type"} keyword for type parameter $identifier"""
686+
687+
val explanation = hl"""|This happens when you add modifiers like ${"private"} or ${"protected"}
688+
|to your type parameter definition without adding the ${"type"} keyword.
689+
|
690+
|Add ${"type"} to your code, e.g.:
691+
|${s"trait A[${mods.flags} type $identifier]"}
692+
|""".stripMargin
680693
}
681694
}

0 commit comments

Comments
 (0)