Skip to content

Commit

Permalink
doInterpolatedStringLiteral: handle empty string special case
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyCat committed Mar 2, 2024
1 parent e8ee268 commit c848416
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ abstract class BaseTranslator(val provider: TypeProvider)

// f-strings
def doInterpolatedStringLiteral(exprs: Seq[Ast.expr]): String =
exprs.map(anyToStr).mkString(" + ")
if (exprs.isEmpty) {
doStringLiteral("")
} else {
exprs.map(anyToStr).mkString(" + ")
}

def anyToStr(value: Ast.expr): String = {
detectType(value) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ class PHPTranslator(provider: TypeProvider, config: RuntimeConfig) extends BaseT
s"max(${translate(a)})"

override def doInterpolatedStringLiteral(exprs: Seq[Ast.expr]): String =
exprs.map(anyToStr).mkString(" . ")
if (exprs.isEmpty) {
doStringLiteral("")
} else {
exprs.map(anyToStr).mkString(" . ")
}

val namespaceRef = if (config.phpNamespace.isEmpty) {
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,9 @@ class PerlTranslator(provider: TypeProvider, importList: ImportList) extends Bas
s"${translate(value)}->size()"

override def doInterpolatedStringLiteral(exprs: Seq[Ast.expr]): String =
exprs.map(anyToStr).mkString(" . ")
if (exprs.isEmpty) {
doStringLiteral("")
} else {
exprs.map(anyToStr).mkString(" . ")
}
}

0 comments on commit c848416

Please sign in to comment.