Skip to content

Commit bda8348

Browse files
committed
Add WasTypedInfix sticky attachment and push it to Apply nodes that are typed infix
1 parent 70a169a commit bda8348

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ object desugar {
6767
*/
6868
val TrailingForMap: Property.Key[Unit] = Property.StickyKey()
6969

70+
val WasTypedInfix: Property.Key[Unit] = Property.StickyKey()
71+
7072
/** What static check should be applied to a Match? */
7173
enum MatchCheck {
7274
case None, Exhaustive, IrrefutablePatDef, IrrefutableGenFrom
@@ -1667,10 +1669,12 @@ object desugar {
16671669
case _ =>
16681670
Apply(sel, arg :: Nil)
16691671

1670-
if op.name.isRightAssocOperatorName then
1672+
val apply = if op.name.isRightAssocOperatorName then
16711673
makeOp(right, left, Span(op.span.start, right.span.end))
16721674
else
16731675
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
1676+
apply.pushAttachment(WasTypedInfix, ())
1677+
return apply
16741678
}
16751679

16761680
/** Translate throws type `A throws E1 | ... | En` to

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import printing.Highlighting.*
1414
import printing.Formatting
1515
import ErrorMessageID.*
1616
import ast.Trees
17+
import ast.desugar
1718
import config.{Feature, MigrationVersion, ScalaVersion}
1819
import transform.patmat.Space
1920
import transform.patmat.SpaceEngine
@@ -370,7 +371,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
370371
case Some(tree) if shouldSuggestNN =>
371372
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString
372373
val replacement = tree match
373-
case a @ Apply(_, _) if a.applyKind == ApplyKind.Using =>
374+
case a @ Apply(_, _) if !a.hasAttachment(desugar.WasTypedInfix) =>
374375
content + ".nn"
375376
case _ @ (Select(_, _) | Ident(_)) => content + ".nn"
376377
case _ => "(" + content + ").nn"

compiler/test/dotty/tools/dotc/reporting/CodeActionTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class CodeActionTest extends DottyTest:
249249
| def q(s2: String, s3: String): String | Null = null
250250
|}
251251
| val s: String = ???
252-
| val t: String = (s.q(s, s)).nn""".stripMargin,
252+
| val t: String = s.q(s, s).nn""".stripMargin,
253253
ctxx = ctxx
254254
)
255255

0 commit comments

Comments
 (0)