Skip to content

Commit 2887c0a

Browse files
committed
Make check look intentional per review
1 parent 12b9217 commit 2887c0a

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,20 @@ class TypedFormatChecker(partsElems: List[Tree], parts: List[String], args: List
228228
case _ => true
229229

230230
def lintToString(arg: Type): Unit =
231-
def check(tp: Type): Boolean = tp.widen match
231+
def checkIsStringify(tp: Type): Boolean = tp.widen match
232232
case OrType(tp1, tp2) =>
233-
check(tp1) || check(tp2)
233+
checkIsStringify(tp1) || checkIsStringify(tp2)
234234
case tp =>
235-
if tp =:= defn.StringType then
236-
false
237-
else if tp =:= defn.UnitType then
238-
warningAt(CC)("interpolated Unit value")
239-
true
240-
else if !tp.isPrimitiveValueType then
241-
warningAt(CC)("interpolation uses toString")
242-
true
243-
else
244-
false
245-
if ctx.settings.Whas.toStringInterpolated && kind == StringXn && check(arg) then
246-
()
235+
!(tp =:= defn.StringType)
236+
&& {
237+
tp =:= defn.UnitType
238+
&& { warningAt(CC)("interpolated Unit value"); true }
239+
||
240+
!tp.isPrimitiveValueType
241+
&& { warningAt(CC)("interpolation uses toString"); true }
242+
}
243+
if ctx.settings.Whas.toStringInterpolated && kind == StringXn then
244+
checkIsStringify(arg): Unit
247245

248246
// what arg type if any does the conversion accept
249247
def acceptableVariants: List[Type] =

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ class StringInterpolatorOpt extends MiniPhase:
110110
result
111111
end mkConcat
112112
def lintToString(t: Tree): Unit =
113-
def check(tp: Type): Boolean = tp.widen match
113+
def checkIsStringify(tp: Type): Boolean = tp.widen match
114114
case OrType(tp1, tp2) =>
115-
check(tp1) || check(tp2)
115+
checkIsStringify(tp1) || checkIsStringify(tp2)
116116
case tp =>
117-
if tp =:= defn.StringType then
118-
false
119-
else if tp =:= defn.UnitType then
120-
report.warning("interpolated Unit value", t.srcPos)
121-
true
122-
else if !tp.isPrimitiveValueType then
123-
report.warning("interpolation uses toString", t.srcPos)
124-
true
125-
else
126-
false
127-
if ctx.settings.Whas.toStringInterpolated && check(t.tpe) then
128-
()
117+
!(tp =:= defn.StringType)
118+
&& {
119+
tp =:= defn.UnitType
120+
&& { report.warning("interpolated Unit value", t.srcPos); true }
121+
||
122+
!tp.isPrimitiveValueType
123+
&& { report.warning("interpolation uses toString", t.srcPos); true }
124+
}
125+
if ctx.settings.Whas.toStringInterpolated then
126+
checkIsStringify(t.tpe): Unit
129127
val sym = tree.symbol
130128
// Test names first to avoid loading scala.StringContext if not used, and common names first
131129
val isInterpolatedMethod =

0 commit comments

Comments
 (0)