Skip to content

Commit

Permalink
SI-8333 can't use modifiers if class is in a block
Browse files Browse the repository at this point in the history
Was caused by the ordering of parser cases. Need to check for definition
first due to the fact that modifiers unquote looks like identifier from
parser point of view.
  • Loading branch information
densh committed Feb 28, 2014
1 parent 13e7b81 commit 6ec0f2f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -3096,10 +3096,6 @@ self =>
stats ++= importClause()
acceptStatSepOpt()
}
else if (isExprIntro) {
stats += statement(InBlock)
if (!isCaseDefEnd) acceptStatSep()
}
else if (isDefIntro || isLocalModifier || isAnnotation) {
if (in.token == IMPLICIT) {
val start = in.skipToken()
Expand All @@ -3110,6 +3106,10 @@ self =>
}
acceptStatSepOpt()
}
else if (isExprIntro) {
stats += statement(InBlock)
if (!isCaseDefEnd) acceptStatSep()
}
else if (isStatSep) {
in.nextToken()
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala
Expand Up @@ -118,6 +118,8 @@ trait Parsers { self: Quasiquotes =>

override def isTemplateIntro: Boolean = super.isTemplateIntro || (isHole && lookingAhead { isTemplateIntro })

override def isDefIntro: Boolean = super.isDefIntro || (isHole && lookingAhead { isDefIntro })

override def isDclIntro: Boolean = super.isDclIntro || (isHole && lookingAhead { isDclIntro })

override def isStatSep(token: Int) = token == EOF || super.isStatSep(token)
Expand Down
Expand Up @@ -9,7 +9,7 @@ object DefinitionConstructionProps
with ValDefConstruction
with PatDefConstruction
with DefConstruction
with PackageConstruction
with PackageConstruction
with ImportConstruction {

val x: Tree = q"val x: Int"
Expand Down Expand Up @@ -81,6 +81,10 @@ trait ClassConstruction { self: QuasiquoteProperties =>
assertEqAst(q" class C($privx)", " class C(x: Int) ")
assertEqAst(q"case class C($privx)", "case class C(private[this] val x: Int)")
}

property("SI-8333") = test {
assertEqAst(q"{ $NoMods class C }", "{ class C }")
}
}

trait TraitConstruction { self: QuasiquoteProperties =>
Expand Down

0 comments on commit 6ec0f2f

Please sign in to comment.