Skip to content

Commit b017ba4

Browse files
committed
Don't auto-tuple if expected type is a tuple
1 parent a60178d commit b017ba4

File tree

5 files changed

+18
-37
lines changed

5 files changed

+18
-37
lines changed

compiler/src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait UniqueMessagePositions extends Reporter {
2121
m.pos.exists && {
2222
var shouldHide = false
2323
for (pos <- m.pos.start to m.pos.end) {
24-
positions get (ctx.source, pos) match {
24+
positions.get((ctx.source, pos)) match {
2525
case Some(level) if level >= m.level => shouldHide = true
2626
case _ => positions((ctx.source, pos)) = m.level
2727
}

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,40 @@ import core.Mode
99

1010
object trace {
1111

12-
@inline
12+
@`inline`
1313
def onDebug[TD](question: => String)(op: => TD)(implicit ctx: Context): TD =
1414
conditionally(ctx.settings.YdebugTrace.value, question, false)(op)
1515

16-
@inline
16+
@`inline`
1717
def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC = {
1818
def op1 = op
1919
if (Config.tracingEnabled && cond) apply[TC](question, Printers.default, show)(op1)
2020
else op1
2121
}
2222

23-
@inline
23+
@`inline`
2424
def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T = {
2525
def op1 = op
2626
if (!Config.tracingEnabled || printer.eq(config.Printers.noPrinter)) op1
2727
else doTrace[T](question, printer, showOp)(op1)
2828
}
2929

30-
@inline
30+
@`inline`
3131
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T = {
3232
def op1 = op
3333
if (!Config.tracingEnabled || printer.eq(config.Printers.noPrinter)) op1
3434
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
3535
}
3636

37-
@inline
37+
@`inline`
3838
def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =
3939
apply[T](question, printer, false)(op)
4040

41-
@inline
41+
@`inline`
4242
def apply[T](question: => String, show: Boolean)(op: => T)(implicit ctx: Context): T =
4343
apply[T](question, Printers.default, show)(op)
4444

45-
@inline
45+
@`inline`
4646
def apply[T](question: => String)(op: => T)(implicit ctx: Context): T =
4747
apply[T](question, Printers.default, false)(op)
4848

@@ -59,7 +59,7 @@ object trace {
5959
(op: => T)(implicit ctx: Context): T = {
6060
// Avoid evaluating question multiple time, since each evaluation
6161
// may cause some extra logging output.
62-
lazy val q: String = question
62+
@volatile lazy val q: String = question
6363
apply[T](s"==> $q?", (res: Any) => s"<== $q = ${showOp(res)}")(op)
6464
}
6565

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
981981
regularArgs :+ untpd.SeqLiteral(varArgs, untpd.TypeTree()).withPos(tree.pos)
982982
}
983983
else argTypes match {
984-
case argType :: Nil if args.lengthCompare(1) > 0 && supportsAutoTupling(argType, args) =>
984+
case argType :: Nil if args.lengthCompare(1) > 0 && canAutoTuple(args) =>
985985
untpd.Tuple(args) :: Nil
986986
case _ =>
987987
args

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,37 +2032,18 @@ class Typer extends Namer
20322032
}
20332033
}
20342034

2035-
def supportsAutoTupling(tp: Type, args: List[untpd.Tree])(implicit ctx: Context): Boolean = {
2036-
def test(tp: Type): Boolean = tp match {
2037-
case tp: TypeRef =>
2038-
val sym = tp.symbol
2039-
defn.isTupleClass(sym) && defn.arity(sym, str.Tuple) == args.length ||
2040-
defn.isProductClass(sym) && defn.arity(sym, str.Product) == args.length ||
2041-
!sym.isClass && test(tp.underlying)
2042-
case tp: TypeParamRef =>
2043-
val bounds = ctx.typeComparer.bounds(tp)
2044-
test(bounds.lo) || test(bounds.hi)
2045-
case tp: TypeProxy =>
2046-
test(tp.underlying)
2047-
case _ =>
2048-
false
2049-
}
2050-
test(tp) || {
2051-
val pos = Position(args.map(_.pos.start).min, args.map(_.pos.end).max)
2052-
ctx.testScala2Mode(
2053-
i"""auto-tupling is no longer supported in this case,
2054-
|arguments now need to be enclosed in parentheses (...).""",
2055-
pos, { patch(pos.startPos, "("); patch(pos.endPos, ")") })
2056-
}
2035+
def canAutoTuple(args: List[untpd.Tree])(implicit ctx: Context): Boolean = {
2036+
val pos = Position(args.map(_.pos.start).min, args.map(_.pos.end).max)
2037+
ctx.testScala2Mode(
2038+
i"""auto-tupling is no longer supported in this case,
2039+
|arguments now need to be enclosed in parentheses (...).""",
2040+
pos, { patch(pos.startPos, "("); patch(pos.endPos, ")") })
20572041
}
20582042

20592043
def takesAutoTupledArgs(tp: Type, sym: Symbol, args: List[untpd.Tree])(implicit ctx: Context): Boolean = tp match {
20602044
case tp: MethodicType =>
20612045
tp.firstParamTypes match {
2062-
case ptype :: Nil =>
2063-
!ptype.isRepeatedParam && {
2064-
sym.name.isOpName || supportsAutoTupling(ptype, args)
2065-
}
2046+
case ptype :: Nil => !ptype.isRepeatedParam && (sym.name.isOpName || canAutoTuple(args))
20662047
case _ => false
20672048
}
20682049
case tp: TermRef =>

tests/run/t8610.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
case class X(name: String) {
44
def x = "Hi, $name" // missing interp
55
def f(p: (Int, Int)): Int = p._1 * p._2
6-
def g = f(3, 4) // adapted
6+
def g = f((3, 4)) // adapted
77
def u: Unit = () // unitarian universalist
88
}
99

0 commit comments

Comments
 (0)