diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 766ecd608995..a3d2b294fdb5 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -636,8 +636,14 @@ object Scanners { if skipping then if r.enclosing.isClosedByUndentAt(nextWidth) then insert(OUTDENT, offset) - else if r.isInstanceOf[InBraces] && !closingRegionTokens.contains(token) then - report.warning("Line is indented too far to the left, or a `}` is missing", sourcePos()) + else + val checkable = r match + case _: InBraces => true + case InParens(LPAREN, _) => true + case _ => false + if checkable && !closingRegionTokens.contains(token) then + report.warning(s"Line is indented too far to the left, or a ${showToken(r.closedBy)} is missing", + sourcePos()) else if lastWidth < nextWidth || lastWidth == nextWidth && (lastToken == MATCH || lastToken == CATCH) && token == CASE then if canStartIndentTokens.contains(lastToken) then diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 27ab73f0fe4d..86abd427bba0 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -1026,7 +1026,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { addParamssText( addParamssText(keywordStr("extension "), leadingParamss) ~~ (defKeyword ~~ valDefText(nameIdText(tree))).close, - trailingParamss) + trailingParamss) else addParamssText(defKeyword ~~ valDefText(nameIdText(tree)), tree.paramss) diff --git a/tests/neg/syntax-error-recovery.check b/tests/neg/syntax-error-recovery.check index 83b764c3062c..9f6cbaa7bf60 100644 --- a/tests/neg/syntax-error-recovery.check +++ b/tests/neg/syntax-error-recovery.check @@ -96,7 +96,5 @@ | longer explanation available when compiling with `-explain` -- Warning: tests/neg/syntax-error-recovery.scala:61:2 ----------------------------------------------------------------- 61 | println(bam) - | ^^^^^^^ - | Alphanumeric method println is not declared infix; it should not be used as infix operator. - | Instead, use method syntax .println(...) or backticked identifier `println`. - | The latter can be rewritten automatically under -rewrite -source 3.4-migration. + | ^ + | Line is indented too far to the left, or a ')' is missing diff --git a/tests/pos/i22527.scala b/tests/pos/i22527.scala index d222c3311b86..cf67d2e750fb 100644 --- a/tests/pos/i22527.scala +++ b/tests/pos/i22527.scala @@ -1,4 +1,8 @@ +//> using options -Werror + +import annotation.* + def f: Unit = identity( identity: @@ -34,6 +38,7 @@ def orElse(x: Int): Unit = else false, "fail") +@nowarn("msg=Unit") def onlyIf(x: Int): Unit = callme( if (x > 0) @@ -57,8 +62,8 @@ def k(xs: List[Int], y: Int, z: Int) = x + y + z, - y, - z, + y, + z, ) ) diff --git a/tests/warn/i22527.check b/tests/warn/i22527.check new file mode 100644 index 000000000000..b50612e12b57 --- /dev/null +++ b/tests/warn/i22527.check @@ -0,0 +1,22 @@ +-- Warning: tests/warn/i22527.scala:60:10 ------------------------------------------------------------------------------ +60 | y, // warn + | ^ + | Line is indented too far to the left, or a ')' is missing +-- Warning: tests/warn/i22527.scala:61:10 ------------------------------------------------------------------------------ +61 | z, // warn + | ^ + | Line is indented too far to the left, or a ')' is missing +-- Warning: tests/warn/i22527.scala:72:2 ------------------------------------------------------------------------------- +72 | 42 // warn + | ^ + | Line is indented too far to the left, or a ')' is missing +-- Warning: tests/warn/i22527.scala:79:0 ------------------------------------------------------------------------------- +79 |k: // warn + |^ + |Line is indented too far to the left, or a ')' is missing +-- [E190] Potential Issue Warning: tests/warn/i22527.scala:40:6 -------------------------------------------------------- +40 | true, "fail") // warn value discard + | ^^^^ + | Discarded non-Unit value of type Boolean. Add `: Unit` to discard silently. + | + | longer explanation available when compiling with `-explain` diff --git a/tests/warn/i22527.scala b/tests/warn/i22527.scala new file mode 100644 index 000000000000..64cd32617406 --- /dev/null +++ b/tests/warn/i22527.scala @@ -0,0 +1,81 @@ + +def f: Unit = + identity( + identity: + class X extends AnyRef, Serializable + 42 + ) + +def test: Unit = + assert( + identity: + true, + "ok" + ) + +def toss: Unit = + assert( + throw + null, + "ok" + ) +def raise: Unit = + assert( + throw + null, "ok" // ok now + ) + +def callme[A](x: => A, msg: String) = try x.toString catch case t: RuntimeException => msg + +def orElse(x: Int): Unit = + callme( + if x > 0 then + true + else + false, "fail") + +def onlyIf(x: Int): Unit = + callme( + if (x > 0) + true, "fail") // warn value discard + +def h(xs: List[Int]) = + xs.foldLeft(0) + ( + (acc, x) => + acc + + x, + ) + +def sum(x: Int, y: Int, z: Int) = x+y+z + +def k(xs: List[Int], y: Int, z: Int) = + xs.foldLeft(0) + ( + (acc, x) => + sum( + x + + y + + z, + y, // warn + z, // warn + ) + ) + +object `arrow eol`: + def f(g: Int => Int, i: Int): Int = g(i) + def g(map: Int => Int): Int => Int = map + def k(i: => Int) = i + def test = + f( + g(_ + 1), + 42 // warn + ) + def test2 = + f( + g: + x => + x + 1, +k: // warn + 42 + )