Skip to content

Commit

Permalink
Merge pull request #2728 from tgodzik/fix-indented-macro
Browse files Browse the repository at this point in the history
Don't allow indentation for macro definitions
  • Loading branch information
tgodzik committed Apr 14, 2022
2 parents 0d26443 + cc6275b commit 62e10b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,14 @@ class ScannerTokens(tokens: Tokens, input: Input)(implicit dialect: Dialect) {
trait CanStartIndent {
def unapply(token: Token): Boolean = token match {
case _: KwYield | _: KwTry | _: KwCatch | _: KwFinally | _: KwMatch | _: KwDo | _: KwFor |
_: KwThen | _: KwElse | _: Equals | _: KwWhile | _: KwIf | _: RightArrow | _: KwReturn |
_: KwThen | _: KwElse | _: KwWhile | _: KwIf | _: RightArrow | _: KwReturn |
_: LeftArrow | _: ContextArrow =>
true
case _: Equals =>
token.next match {
case _: KwMacro => false
case _ => true
}
case _: KwWith =>
token.next match {
case _: KwImport | _: KwExport | DefIntro() => true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,4 +1300,23 @@ class MinorDottySuite extends BaseDottySuite {
)
}

test("#2727-newline-macro") {

runTestAssert[Stat](
"""|implicit def generate[T](value: T): Clue[T] =
| macro MacroCompatScala2.clueImpl""".stripMargin,
assertLayout =
Some("implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl")
)(
Defn.Macro(
List(Mod.Implicit()),
Term.Name("generate"),
List(Type.Param(Nil, Type.Name("T"), Nil, Type.Bounds(None, None), Nil, Nil)),
List(List(Term.Param(Nil, Term.Name("value"), Some(Type.Name("T")), None))),
Some(Type.Apply(Type.Name("Clue"), List(Type.Name("T")))),
Term.Select(Term.Name("MacroCompatScala2"), Term.Name("clueImpl"))
)
)
}

}

0 comments on commit 62e10b7

Please sign in to comment.