-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw a more informative error when scala_macro_library isn't used (#…
…1680) * Throw a more informative error when scala_macro_library isn't used * fixup! Fixed failing tests * fixup! Catch `ClassFormatError`s in ScalacInvoker --------- Co-authored-by: Jaden Peterson <[email protected]>
- Loading branch information
Showing
5 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("//scala:scala.bzl", "scala_library", "scala_macro_library") | ||
|
||
scala_library( | ||
name = "incorrect-macro", | ||
srcs = ["IdentityMacro.scala"], | ||
) | ||
|
||
scala_macro_library( | ||
name = "correct-macro", | ||
srcs = ["IdentityMacro.scala"], | ||
) | ||
|
||
scala_library( | ||
name = "incorrect-macro-user", | ||
srcs = ["MacroUser.scala"], | ||
tags = ["manual"], | ||
deps = [":incorrect-macro"], | ||
) | ||
|
||
scala_library( | ||
name = "correct-macro-user", | ||
srcs = ["MacroUser.scala"], | ||
deps = [":correct-macro"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package macros | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox | ||
|
||
object IdentityMacro { | ||
def identityMacro[A](value: A): A = macro identityMacroImpl[A] | ||
def identityMacroImpl[A](context: blackbox.Context)(value: context.Expr[A]): context.Expr[A] = value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package macros | ||
|
||
object Main { | ||
def main(arguments: Array[String]): Unit = println(IdentityMacro.identityMacro("Hello, world!")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# shellcheck source=./test_runner.sh | ||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
. "${dir}"/test_runner.sh | ||
. "${dir}"/test_helper.sh | ||
runner=$(get_test_runner "${1:-local}") | ||
|
||
incorrect_macro_user_does_not_build() { | ||
(! bazel build //test/macros:incorrect-macro-user) |& | ||
grep --fixed-strings 'Build failure during macro expansion. You may have declared a target containing a macro as a `scala_library` target instead of a `scala_macro_library` target' | ||
} | ||
|
||
correct_macro_user_builds() { | ||
bazel build //test/macros:correct-macro-user | ||
} | ||
|
||
$runner incorrect_macro_user_does_not_build | ||
$runner correct_macro_user_builds |