Skip to content

Drop with after class #11448

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

Merged
merged 1 commit into from
Feb 18, 2021
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
19 changes: 9 additions & 10 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ object Parsers {

def possibleTemplateStart(isNew: Boolean = false): Unit =
in.observeColonEOL()
if in.token == COLONEOL || in.token == WITH then
if in.token == COLONEOL then
if in.lookahead.isIdent(nme.end) then in.token = NEWLINE
else
in.nextToken()
Expand Down Expand Up @@ -2333,7 +2333,7 @@ object Parsers {
possibleTemplateStart()
val parents =
if in.isNestedStart then Nil
else constrApps(commaOK = false)
else constrApps(exclude = COMMA)
colonAtEOLOpt()
possibleTemplateStart(isNew = true)
parents match {
Expand Down Expand Up @@ -3536,7 +3536,7 @@ object Parsers {
val parents =
if (in.token == EXTENDS) {
in.nextToken()
constrApps(commaOK = true)
constrApps()
}
else Nil
Template(constr, parents, Nil, EmptyValDef, Nil)
Expand Down Expand Up @@ -3670,16 +3670,16 @@ object Parsers {

/** ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp})
*/
def constrApps(commaOK: Boolean): List[Tree] =
def constrApps(exclude: Token = EMPTY): List[Tree] =
val t = constrApp()
val ts =
if in.token == WITH || commaOK && in.token == COMMA then
val tok = in.token
if (tok == WITH || tok == COMMA) && tok != exclude then
in.nextToken()
constrApps(commaOK)
constrApps(exclude = if tok == WITH then COMMA else WITH)
else Nil
t :: ts


/** `{`with` ConstrApp} but no EOL allowed after `with`.
*/
def withConstrApps(): List[Tree] =
Expand All @@ -3704,7 +3704,7 @@ object Parsers {
in.sourcePos())
Nil
}
else constrApps(commaOK = true)
else constrApps()
}
else Nil
newLinesOptWhenFollowedBy(nme.derives)
Expand Down Expand Up @@ -3758,8 +3758,7 @@ object Parsers {

/** with Template, with EOL <indent> interpreted */
def withTemplate(constr: DefDef, parents: List[Tree]): Template =
if in.token != WITH then syntaxError(em"`with` expected")
possibleTemplateStart() // consumes a WITH token
accept(WITH)
val (self, stats) = templateBody()
Template(constr, parents, Nil, self, stats)
.withSpan(Span(constr.span.orElse(parents.head.span).start, in.lastOffset))
Expand Down
10 changes: 5 additions & 5 deletions tests/neg/language-import.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object a with
object a:
val l = _root_.scala.language
import l.noAutoTupling // error
import l.experimental.genericNumberLiterals // error
Expand All @@ -7,16 +7,16 @@ object a with
val language = b
import language.experimental.genericNumberLiterals // error

object b with
object b:
val strictEquality = 22
object experimental with
object experimental:
val genericNumberLiterals = 22

object c with
object c:
val language = b
import b.strictEquality

object d with
object d:
import language.experimental.genericNumberLiterals // ok
import scala.language.noAutoTupling // ok
import _root_.scala.language.strictEquality // ok
Expand Down