Skip to content

Make script wrapper satisfy compiler checks #2414

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case object ClassCodeWrapper extends CodeWrapper {
|
| def main(args: Array[String]): Unit = {
| args$$set(args)
| script.hashCode() // hashCode to clear scalac warning about pure expression in statement position
| val _ = script.hashCode() // hashCode to clear scalac warning about pure expression in statement position
| }
|}
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case object ObjectCodeWrapper extends CodeWrapper {
| }
| def main(args: Array[String]): Unit = {
| args$$set(args)
| $funHashCodeMethod // hasCode to clear scalac warning about pure expression in statement position
| val _ = $funHashCodeMethod // hashCode to clear scalac warning about pure expression in statement position
| }
|}
|""".stripMargin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,31 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions =>
}
}
}

test("script wrappers satisfy strict compiler flags") {
val inputs = TestInputs(
os.rel / "strictClassWrapper.sc" ->
"""//> using scala 3.3.1
|//> using options -Werror -Wnonunit-statement -Wunused:all -Wvalue-discard
|//> using options -Yno-experimental -Ysafe-init -deprecation -feature -language:strictEquality
|//> using options -new-syntax -old-syntax -unchecked -no-indent
|
|println(strictObjectWrapper.Foo(42).x)
|""".stripMargin,

os.rel / "strictObjectWrapper.sc" ->
"""//> using objectWrapper
|//> using scala 3.3.1
|//> using options -Werror -Wnonunit-statement -Wunused:all -Wvalue-discard
|//> using options -Yno-experimental -Ysafe-init -deprecation -feature -language:strictEquality
|//> using options -new-syntax -old-syntax -unchecked -no-indent
|
|case class Foo(x: Int)
|""".stripMargin
)
inputs.fromRoot { root =>
val p = os.proc(TestUtil.cli, "--power", "strictClassWrapper.sc", "strictObjectWrapper.sc").call(cwd = root)
expect(p.out.trim() == "42")
}
}
}