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

fix issue 462 - MatchError in Output[String] -> Output[NonEmptyString] inference #465

Merged
merged 1 commit into from
Apr 19, 2024
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
4 changes: 4 additions & 0 deletions core/src/main/scala/besom/util/NonEmptyString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ object NonEmptyString:
handleParts(parts)
case '{ scala.StringContext.apply(${ Varargs(parts) }: _*).pulumi(${ Varargs(_) }: _*)(using ${ xd }: Context) } =>
handleParts(parts)
case _ =>
report.errorAndAbort(
"This is an Output of a dynamic String which can't be inferred to be a NonEmptyString! Use `.flatMap(_.toNonEmptyOutput)` instead."
)

end fromStringOutputImpl

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/besom/util/CompileAssertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ trait CompileAssertions:

private val NL = System.lineSeparator()

inline def failsToCompile(inline code: String): Unit =
transparent inline def failsToCompile(inline code: String): Unit =
assert(
!scala.compiletime.testing.typeChecks(code),
s"Code compiled correctly when expecting type errors:$NL$code"
)

inline def compiles(inline code: String): Unit =
transparent inline def compiles(inline code: String): Unit =
val errors = scala.compiletime.testing.typeCheckErrors(code)
if errors.nonEmpty then
val errorMessages = errors.map(_.message).mkString(NL)
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/scala/besom/util/NonEmptyStringTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,31 @@ class NonEmptyStringTest extends munit.FunSuite with CompileAssertions:
case None => ()
case Some(_) => fail("apply doesn't work")
}

test("issue 462") {
val errors = scala.compiletime.testing.typeCheckErrors("""
import besom.*
given Context = ???

def requireString(key: NonEmptyString)(using Context): Output[String] = ???

val s: Output[NonEmptyString] = requireString("stuff")
""")

assert(errors.size == 1)
assert(
errors.head.message.contains(
"This is an Output of a dynamic String which can't be inferred to be a NonEmptyString! Use `.flatMap(_.toNonEmptyOutput)` instead."
)
)

compiles("""
import besom.*
given Context = ???

def requireString(key: NonEmptyString)(using Context): Output[String] = ???

val s: Output[NonEmptyString] = requireString("stuff").flatMap(_.toNonEmptyOutput)
""")
}
end NonEmptyStringTest
Loading