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

Format scala-3 MacroCompat with scala3 runner #518

Merged
merged 7 commits into from
May 19, 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
8 changes: 6 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.1"
version = "3.5.4"

assumeStandardLibraryStripMargin = true

Expand All @@ -8,7 +8,11 @@ docstrings.style = Asterisk

project.git=true
project.excludeFilters = [
".*scala-3*"
"LinesSuite.scala"
]
runner.dialect = scala212
fileOverride {
"glob:**/src/{main,test}/scala-3/**" {
runner.dialect = scala3
}
}
12 changes: 8 additions & 4 deletions munit/shared/src/main/scala-2/munit/internal/MacroCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ object MacroCompat {
def locationImpl(c: Context): c.Tree = MacroCompatScala2.locationImpl(c)

trait ClueMacro {
implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl
implicit def generate[T](value: T): Clue[T] =
macro MacroCompatScala2.clueImpl
}

@deprecated("Use MacroCompatScala2.clueImpl instead", "2020-01-06")
def clueImpl(c: Context)(value: c.Tree): c.Tree = MacroCompatScala2.clueImpl(c)(value)
def clueImpl(c: Context)(value: c.Tree): c.Tree =
MacroCompatScala2.clueImpl(c)(value)

trait CompileErrorMacro {
def compileErrors(code: String): String = macro MacroCompatScala2.compileErrorsImpl
def compileErrors(code: String): String =
macro MacroCompatScala2.compileErrorsImpl
}

@deprecated("Use MacroCompatScala2.compileErrorsImpl instead", "2020-01-06")
def compileErrorsImpl(c: Context)(value: c.Tree): c.Tree = MacroCompatScala2.compileErrorsImpl(c)(value)
def compileErrorsImpl(c: Context)(value: c.Tree): c.Tree =
MacroCompatScala2.compileErrorsImpl(c)(value)

}
33 changes: 19 additions & 14 deletions munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,41 @@ object MacroCompat {
val pos = Position.ofMacroExpansion
val path = pos.sourceFile.jpath.toString
val startLine = pos.startLine + 1
'{ new Location(${Expr(path)}, ${Expr(startLine)}) }
'{ new Location(${ Expr(path) }, ${ Expr(startLine) }) }
}

trait ClueMacro {
inline implicit def generate[T](value: T): Clue[T] = ${ clueImpl('value) }
implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl
implicit def generate[T](value: T): Clue[T] = macro
MacroCompatScala2.clueImpl
}

def clueImpl[T: Type](value: Expr[T])(using Quotes): Expr[Clue[T]] = {
import quotes.reflect._
val source = value.asTerm.pos.sourceCode.getOrElse("")
val valueType = TypeTree.of[T].show(using Printer.TreeShortCode)
'{ new Clue(${Expr(source)}, $value, ${Expr(valueType)}) }
'{ new Clue(${ Expr(source) }, $value, ${ Expr(valueType) }) }
}


trait CompileErrorMacro {
inline def compileErrors(inline code: String): String = {
val errors = scala.compiletime.testing.typeCheckErrors(code)
errors.map { error =>
val indent = " " * (error.column - 1)
val trimMessage = error.message.linesIterator.map { line =>
if (line.matches(" +")) ""
else line
}.mkString("\n")
val separator = if (error.message.contains('\n')) "\n" else " "
s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^"
}.mkString("\n")
errors
.map { error =>
val indent = " " * (error.column - 1)
val trimMessage = error.message.linesIterator
.map { line =>
if (line.matches(" +")) ""
else line
}
.mkString("\n")
val separator = if (error.message.contains('\n')) "\n" else " "
s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^"
}
.mkString("\n")
}
def compileErrors(code: String): String = macro MacroCompatScala2.compileErrorsImpl
def compileErrors(code: String): String = macro
MacroCompatScala2.compileErrorsImpl
}

}