Skip to content

Commit e788f89

Browse files
committed
Lint concatenation
1 parent 12673fa commit e788f89

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/FormatChecker.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class TypedFormatChecker(partsElems: List[Tree], parts: List[String], args: List
222222
case _ => true
223223

224224
def lintToString(arg: Type): Unit =
225-
if ctx.settings.WtoStringInterpolated.value && kind == StringXn && !(arg =:= defn.StringType) && !isPrimitiveValueType(arg)
225+
if ctx.settings.WtoStringInterpolated.value && kind == StringXn && !(arg.widen =:= defn.StringType) && !arg.isPrimitiveValueType
226226
then warningAt(CC)("interpolation uses toString")
227227

228228
// what arg type if any does the conversion accept

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ class StringInterpolatorOpt extends MiniPhase:
9696
def mkConcat(strs: List[Literal], elems: List[Tree]): Tree =
9797
val stri = strs.iterator
9898
val elemi = elems.iterator
99-
var result: Tree = stri.next
99+
var result: Tree = stri.next()
100100
def concat(tree: Tree): Unit =
101101
result = result.select(defn.String_+).appliedTo(tree).withSpan(tree.span)
102102
while elemi.hasNext
103103
do
104-
concat(elemi.next)
105-
val str = stri.next
104+
val elem = elemi.next()
105+
lintToString(elem)
106+
concat(elem)
107+
val str = stri.next()
106108
if !str.const.stringValue.isEmpty then concat(str)
107109
result
108110
end mkConcat
111+
def lintToString(t: Tree): Unit =
112+
val arg: Type = t.tpe
113+
if ctx.settings.WtoStringInterpolated.value && !(arg.widen =:= defn.StringType) && !arg.isPrimitiveValueType
114+
then report.warning("interpolation uses toString", t.srcPos)
109115
val sym = tree.symbol
110116
// Test names first to avoid loading scala.StringContext if not used, and common names first
111117
val isInterpolatedMethod =

0 commit comments

Comments
 (0)