Skip to content

Infix operation desugaring should preserve original span #22703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) =>
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/neg/byname-nullables1.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 12 additions & 12 deletions tests/neg-custom-args/captures/sepchecks2.check
Original file line number Diff line number Diff line change
Expand Up @@ -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
| ^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/run/typeCheckErrors.check
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 2 additions & 2 deletions tests/warn/21557.check
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/warn/nonunit-statement.check
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/warn-value-discard.check
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading