Skip to content

Commit 2e864c0

Browse files
hermesespinolaallanrenucci
authored andcommitted
Error on TypedefOrDcl (#3325)
1 parent b7fbb39 commit 2e864c0

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ object Parsers {
21562156
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
21572157
TypeDef(name, lambdaAbstract(tparams, typeBounds())).withMods(mods).setComment(in.getDocComment(start))
21582158
case _ =>
2159-
syntaxErrorOrIncomplete("`=', `>:', or `<:' expected")
2159+
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
21602160
EmptyTree
21612161
}
21622162
}

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public enum ErrorMessageID {
102102
UncheckedTypePatternID,
103103
ExtendFinalClassID,
104104
EnumCaseDefinitionInNonEnumOwnerID,
105+
ExpectedTypeBoundOrEqualsID,
105106
;
106107

107108
public int errorNumber() {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ object messages {
17701770
|"""
17711771
}
17721772

1773-
case class ExtendFinalClass(clazz:Symbol, finalClazz: Symbol)(implicit ctx: Context)
1773+
case class ExtendFinalClass(clazz:Symbol, finalClazz: Symbol)(implicit ctx: Context)
17741774
extends Message(ExtendFinalClassID) {
17751775
val kind = "Syntax"
17761776
val msg = hl"$clazz cannot extend ${"final"} $finalClazz"
@@ -1786,4 +1786,22 @@ object messages {
17861786
|If you want to create an ${"enum"} case, make sure the corresponding ${"enum class"} exists
17871787
|and has the ${"enum"} keyword."""
17881788
}
1789+
1790+
case class ExpectedTypeBoundOrEquals(found: Token)(implicit ctx: Context)
1791+
extends Message(ExpectedTypeBoundOrEqualsID) {
1792+
val kind = "Syntax"
1793+
val msg = hl"${"="}, ${">:"}, or ${"<:"} expected, but ${Tokens.showToken(found)} found"
1794+
1795+
val explanation =
1796+
hl"""Type parameters and abstract types may be constrained by a type bound.
1797+
|Such type bounds limit the concrete values of the type variables and possibly
1798+
|reveal more information about the members of such types.
1799+
|
1800+
|A lower type bound ${"B >: A"} expresses that the type variable ${"B"}
1801+
|refers to a supertype of type ${"A"}.
1802+
|
1803+
|An upper type bound ${"T <: A"} declares that type variable ${"T"}
1804+
|refers to a subtype of type ${"A"}.
1805+
|"""
1806+
}
17891807
}

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
10241024
val EnumCaseDefinitionInNonEnumOwner(owner) :: Nil = messages
10251025
assertEquals("object Qux", owner.show)
10261026
}
1027+
1028+
@Test def expectedTypeBoundOrEquals =
1029+
checkMessagesAfter("frontend") {
1030+
"""object typedef {
1031+
| type asd > Seq
1032+
|}
1033+
""".stripMargin
1034+
}.expect { (ictx, messages) =>
1035+
implicit val ctx: Context = ictx
1036+
1037+
assertMessageCount(1, messages)
1038+
val ExpectedTypeBoundOrEquals(found) :: Nil = messages
1039+
assertEquals(Tokens.IDENTIFIER, found)
1040+
}
10271041
}

0 commit comments

Comments
 (0)