Skip to content

-Wtostring-interpolated warns on an if expression of type String #23361

Open
@johnduffell

Description

@johnduffell

Compiler version

3.7.1-RC1

Minimized code

With scalacOptions including

    "-Wtostring-interpolated",

compile this code:

val shouldCaps = true
val greeting = s"Hello ${if (shouldCaps) "WORLD" else "world"}"
println(greeting)

see https://scastie.scala-lang.org/Y9lVvpVjRUeL7P08bs8Heg

Output

there is a warning raised on line 2:
"interpolation uses toString"

Expectation

compiles without warnings, as the type of the expression is a String

Additional info

Also fails on 2.13.16
Feature introduced in #20578

Metadata

Metadata

Assignees

Labels

itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions