From cb2e7674da66f13df0a7acd0af6ad595a743a7fc Mon Sep 17 00:00:00 2001 From: rochala Date: Tue, 4 Mar 2025 02:51:41 +0100 Subject: [PATCH] Synthetic applies created during infix op desugaring should have original span --- .../src/dotty/tools/dotc/ast/Desugar.scala | 3 ++- .../neg/byname-nullables1.check | 2 +- .../neg-custom-args/captures/sepchecks2.check | 24 +++++++++---------- tests/run/typeCheckErrors.check | 2 +- tests/warn/21557.check | 4 ++-- tests/warn/nonunit-statement.check | 4 ++-- tests/warn/warn-value-discard.check | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 471a9953c4f0..266055205f68 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1655,7 +1655,7 @@ object desugar { val sel = Select(fn, op.name).withSpan(selectPos) if (left.sourcePos.endLine < op.sourcePos.startLine) sel.pushAttachment(MultiLineInfix, ()) - arg match + val apply = arg match case Parens(arg) => Apply(sel, assignToNamedArg(arg) :: Nil) case Tuple(args) if args.exists(_.isInstanceOf[Assign]) => @@ -1664,6 +1664,7 @@ object desugar { Apply(sel, arg :: Nil).setApplyKind(ApplyKind.InfixTuple) case _ => Apply(sel, arg :: Nil) + apply.withSpan(Span(left.span.start, right.span.end, point = op.span.start)) if op.name.isRightAssocOperatorName then makeOp(right, left, Span(op.span.start, right.span.end)) diff --git a/tests/explicit-nulls/neg/byname-nullables1.check b/tests/explicit-nulls/neg/byname-nullables1.check index 05ec1c811a9e..4f61d3d97841 100644 --- a/tests/explicit-nulls/neg/byname-nullables1.check +++ b/tests/explicit-nulls/neg/byname-nullables1.check @@ -1,4 +1,4 @@ --- Error: tests/explicit-nulls/neg/byname-nullables1.scala:10:6 -------------------------------------------------------- +-- Error: tests/explicit-nulls/neg/byname-nullables1.scala:10:12 ------------------------------------------------------- 10 | f(x.fld != null) // error | ^^^^^^^^^^^^^ | This argument was typed using flow assumptions about mutable variables diff --git a/tests/neg-custom-args/captures/sepchecks2.check b/tests/neg-custom-args/captures/sepchecks2.check index 47a80306f3b7..91a06b543f96 100644 --- a/tests/neg-custom-args/captures/sepchecks2.check +++ b/tests/neg-custom-args/captures/sepchecks2.check @@ -4,20 +4,20 @@ | Separation failure: Illegal access to {c} which is hidden by the previous definition | of value xs with type List[box () => Unit]. | This type hides capabilities {c} --- Error: tests/neg-custom-args/captures/sepchecks2.scala:13:7 --------------------------------------------------------- +-- Error: tests/neg-custom-args/captures/sepchecks2.scala:13:25 -------------------------------------------------------- 13 | foo((() => println(c)) :: Nil, c) // error - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | Separation failure: argument of type List[box () ->{c} Unit] - | to method foo: (xs: List[box () => Unit], y: Object^): Nothing - | corresponds to capture-polymorphic formal parameter xs of type List[box () => Unit] - | and hides capabilities {c}. - | Some of these overlap with the captures of the second argument with type (c : Object^). + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | Separation failure: argument of type List[box () ->{c} Unit] + | to method foo: (xs: List[box () => Unit], y: Object^): Nothing + | corresponds to capture-polymorphic formal parameter xs of type List[box () => Unit] + | and hides capabilities {c}. + | Some of these overlap with the captures of the second argument with type (c : Object^). | - | Hidden set of current argument : {c} - | Hidden footprint of current argument : {c} - | Capture set of second argument : {c} - | Footprint set of second argument : {c} - | The two sets overlap at : {c} + | Hidden set of current argument : {c} + | Hidden footprint of current argument : {c} + | Capture set of second argument : {c} + | Footprint set of second argument : {c} + | The two sets overlap at : {c} -- Error: tests/neg-custom-args/captures/sepchecks2.scala:14:10 -------------------------------------------------------- 14 | val x1: (Object^, Object^) = (c, c) // error | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/run/typeCheckErrors.check b/tests/run/typeCheckErrors.check index 6602c37ea812..903823ca95ee 100644 --- a/tests/run/typeCheckErrors.check +++ b/tests/run/typeCheckErrors.check @@ -1 +1 @@ -List(Error(value check is not a member of Unit,compileError("1" * 2).check(""),22,Typer), Error(argument to compileError must be a statically known String but was: augmentString("1") * 2,compileError("1" * 2).check(""),13,Typer)) +List(Error(value check is not a member of Unit,compileError("1" * 2).check(""),22,Typer), Error(argument to compileError must be a statically known String but was: augmentString("1") * 2,compileError("1" * 2).check(""),17,Typer)) diff --git a/tests/warn/21557.check b/tests/warn/21557.check index 1753960b852a..258559a998b5 100644 --- a/tests/warn/21557.check +++ b/tests/warn/21557.check @@ -1,10 +1,10 @@ --- [E190] Potential Issue Warning: tests/warn/21557.scala:9:16 --------------------------------------------------------- +-- [E190] Potential Issue Warning: tests/warn/21557.scala:9:18 --------------------------------------------------------- 9 | val x: Unit = 1 + 1 // warn | ^^^^^ | Discarded non-Unit value of type Int. Add `: Unit` to discard silently. | | longer explanation available when compiling with `-explain` --- [E176] Potential Issue Warning: tests/warn/21557.scala:10:2 --------------------------------------------------------- +-- [E176] Potential Issue Warning: tests/warn/21557.scala:10:4 --------------------------------------------------------- 10 | 1 + 1 // warn | ^^^^^ | unused value of type (2 : Int) diff --git a/tests/warn/nonunit-statement.check b/tests/warn/nonunit-statement.check index 7e7939e1c163..dc6c3610870f 100644 --- a/tests/warn/nonunit-statement.check +++ b/tests/warn/nonunit-statement.check @@ -14,7 +14,7 @@ 30 | copy() // warn | ^^^^^^ | unused value of type K --- [E176] Potential Issue Warning: tests/warn/nonunit-statement.scala:37:2 --------------------------------------------- +-- [E176] Potential Issue Warning: tests/warn/nonunit-statement.scala:37:5 --------------------------------------------- 37 | 27 +: xs // warn | ^^^^^^^^ | unused value of type List[Int] @@ -63,7 +63,7 @@ 101 | println("false") 102 | j 103 | } --- [E176] Potential Issue Warning: tests/warn/nonunit-statement.scala:116:4 -------------------------------------------- +-- [E176] Potential Issue Warning: tests/warn/nonunit-statement.scala:116:8 -------------------------------------------- 116 | set += a // warn because cannot know whether the `set` was supposed to be consumed or assigned | ^^^^^^^^ | unused value of type scala.collection.mutable.LinkedHashSet[A] diff --git a/tests/warn/warn-value-discard.check b/tests/warn/warn-value-discard.check index dcd6d62c00e0..8146171c115b 100644 --- a/tests/warn/warn-value-discard.check +++ b/tests/warn/warn-value-discard.check @@ -6,7 +6,7 @@ 39 | mutable.Set.empty[String].subtractOne("") // warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | discarded non-Unit value of type scala.collection.mutable.Set[String]. Add `: Unit` to discard silently. --- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:59:4 -------------------------------------------- +-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:59:30 ------------------------------------------- 59 | mutable.Set.empty[String] += "" // warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | discarded non-Unit value of type scala.collection.mutable.Set[String]. Add `: Unit` to discard silently.