🌐 AI搜索 & 代理 主页
Skip to content

Commit effa62a

Browse files
committed
Adapted multiarg infix is just a tuple
1 parent 7d8ebee commit effa62a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/compiler/scala/tools/nsc/typechecker/Adaptations.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ trait Adaptations {
3636
case Apply(_, arg :: Nil) => arg
3737
case _ => EmptyTree
3838
}
39+
def isInfix = t match {
40+
case Apply(_, arg :: Nil) => t.hasAttachment[MultiargInfixAttachment.type]
41+
case _ => false
42+
}
3943
def callString = (
4044
( if (t.symbol.isConstructor) "new " else "" ) +
4145
( t.symbol.owner.decodedName ) +
@@ -86,15 +90,17 @@ trait Adaptations {
8690
true // keep adaptation
8791
}
8892
@inline def warnAdaptation = {
89-
if (settings.warnAdaptedArgs) context.warning(t.pos, adaptWarningMessage(
93+
if (settings.warnAdaptedArgs && !isInfix) context.warning(t.pos, adaptWarningMessage(
9094
s"adapted the argument list to the expected ${args.size}-tuple: add additional parens instead"),
9195
WarningCategory.LintAdaptedArgs)
9296
true // keep adaptation
9397
}
94-
if (args.isEmpty) {
95-
if (currentRun.isScala3) noAdaptation else deprecatedAdaptation
96-
} else
98+
if (args.nonEmpty)
9799
warnAdaptation
100+
else if (currentRun.isScala3)
101+
noAdaptation
102+
else
103+
deprecatedAdaptation
98104
}
99105
}
100106
}

test/files/pos/t5073.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

2+
//scalac: -Xlint -Werror
3+
24
trait Test {
35

4-
trait T[A]
6+
trait T[_]
57

68
class C {
79
def -:(x: AnyRef): T[x.type] = ???
@@ -33,4 +35,9 @@ class B {
3335
}
3436

3537
// issue 11117
36-
class A2[B](val b: B) { def c: List[b.type] = b :: Nil }
38+
class A2[B2](val b: B2) { def c: List[b.type] = b :: Nil }
39+
40+
// don't bug me about adapting a tuple when I wrote a tuple arg to infix
41+
class `lukas warned me about this and I brushed him off but that was last year before pandemic` {
42+
def `tuple in infix expression must not warn` = (42, 27) :: Nil
43+
}

0 commit comments

Comments
 (0)