Skip to content

Commit

Permalink
fix issue 462 - pulumi string interpolation inference macro threw Mat…
Browse files Browse the repository at this point in the history
…chError on dynamic Output[String] (#465)
  • Loading branch information
lbialy authored Apr 19, 2024
1 parent 360d550 commit 7811f3b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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

0 comments on commit 7811f3b

Please sign in to comment.