Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid misleading error message #14331

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3752,11 +3752,11 @@ object Parsers {
}
else Nil
possibleTemplateStart()
if (isEnum) {
val (self, stats) = withinEnum(templateBody())
if isEnum then
val (self, stats) = withinEnum(templateBody(parents))
Template(constr, parents, derived, self, stats)
}
else templateBodyOpt(constr, parents, derived)
else
templateBodyOpt(constr, parents, derived)
}

/** TemplateOpt = [Template]
Expand All @@ -3779,15 +3779,15 @@ object Parsers {
def templateBodyOpt(constr: DefDef, parents: List[Tree], derived: List[Tree]): Template =
val (self, stats) =
if in.isNestedStart then
templateBody()
templateBody(parents)
else
checkNextNotIndented()
(EmptyValDef, Nil)
Template(constr, parents, derived, self, stats)

def templateBody(rewriteWithColon: Boolean = true): (ValDef, List[Tree]) =
def templateBody(parents: List[Tree], rewriteWithColon: Boolean = true): (ValDef, List[Tree]) =
val r = inDefScopeBraces(templateStatSeq(), rewriteWithColon)
if in.token == WITH then
if in.token == WITH && parents.isEmpty then
syntaxError(EarlyDefinitionsNotSupported())
in.nextToken()
template(emptyConstructor)
Expand All @@ -3796,7 +3796,7 @@ object Parsers {
/** with Template, with EOL <indent> interpreted */
def withTemplate(constr: DefDef, parents: List[Tree]): Template =
accept(WITH)
val (self, stats) = templateBody(rewriteWithColon = false)
val (self, stats) = templateBody(parents, rewriteWithColon = false)
Template(constr, parents, Nil, self, stats)
.withSpan(Span(constr.span.orElse(parents.head.span).start, in.lastOffset))

Expand Down Expand Up @@ -4039,7 +4039,7 @@ object Parsers {
EmptyTree
}

override def templateBody(rewriteWithColon: Boolean): (ValDef, List[Thicket]) = {
override def templateBody(parents: List[Tree], rewriteWithColon: Boolean): (ValDef, List[Thicket]) = {
skipBraces()
(EmptyValDef, List(EmptyTree))
}
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/parent-refinement.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/parent-refinement.scala:5:2 ------------------------------------------------------------------------
5 | with Ordered[Year] { // error
| ^^^^
| end of toplevel definition expected but 'with' found
7 changes: 7 additions & 0 deletions tests/neg/parent-refinement.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

trait Id { type Value }
case class Year(value: Int) extends AnyVal
with Id { type Value = Int }
with Ordered[Year] { // error

}