Skip to content

Commit 6bcec97

Browse files
SuperCl4shtgodzik
authored andcommitted
Add WasTypedInfix sticky attachment and push it to Apply nodes that are typed infix
1 parent c3f1aee commit 6bcec97

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
@@ -53,6 +53,8 @@ object desugar {
5353
*/
5454
val ForArtifact: Property.Key[Unit] = Property.StickyKey()
5555

56+
val WasTypedInfix: Property.Key[Unit] = Property.StickyKey()
57+
5658
/** What static check should be applied to a Match? */
5759
enum MatchCheck {
5860
case None, Exhaustive, IrrefutablePatDef, IrrefutableGenFrom
@@ -1369,10 +1371,12 @@ object desugar {
13691371
case _ =>
13701372
Apply(sel, arg :: Nil)
13711373

1372-
if op.name.isRightAssocOperatorName then
1374+
val apply = if op.name.isRightAssocOperatorName then
13731375
makeOp(right, left, Span(op.span.start, right.span.end))
13741376
else
13751377
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
1378+
apply.pushAttachment(WasTypedInfix, ())
1379+
return apply
13761380
}
13771381

13781382
/** 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, ScalaVersion}
1819
import transform.patmat.Space
1920
import transform.patmat.SpaceEngine
@@ -365,7 +366,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
365366
case Some(tree) if shouldSuggestNN =>
366367
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString
367368
val replacement = tree match
368-
case a @ Apply(_, _) if a.applyKind == ApplyKind.Using =>
369+
case a @ Apply(_, _) if !a.hasAttachment(desugar.WasTypedInfix) =>
369370
content + ".nn"
370371
case _ @ (Select(_, _) | Ident(_)) => content + ".nn"
371372
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
@@ -235,7 +235,7 @@ class CodeActionTest extends DottyTest:
235235
| def q(s2: String, s3: String): String | Null = null
236236
|}
237237
| val s: String = ???
238-
| val t: String = (s.q(s, s)).nn""".stripMargin,
238+
| val t: String = s.q(s, s).nn""".stripMargin,
239239
ctxx = ctxx
240240
)
241241

0 commit comments

Comments
 (0)