Skip to content

Commit 764bc40

Browse files
committed
Lint concatenation
1 parent 3140216 commit 764bc40

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class TypedFormatChecker(partsElems: List[Tree], parts: List[String], args: List
221221
case _ => true
222222

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

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

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

Lines changed: 9 additions & 3 deletions
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)