Skip to content

Revert to Scala 2 rules for handling opening brace on next line #16767

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

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 1 addition & 9 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1353,15 +1353,7 @@ object Parsers {

def argumentStart(): Unit =
colonAtEOLOpt()
if migrateTo3 && in.token == NEWLINE && in.next.token == LBRACE then
in.nextToken()
if in.indentWidth(in.offset) == in.currentRegion.indentWidth then
report.errorOrMigrationWarning(
em"""This opening brace will start a new statement in Scala 3.
|It needs to be indented to the right to keep being treated as
|an argument to the previous expression.${rewriteNotice()}""",
in.sourcePos(), from = `3.0`)
patch(source, Span(in.offset), " ")
newLineOptWhenFollowedBy(LBRACE)

def possibleTemplateStart(isNew: Boolean = false): Unit =
in.observeColonEOL(inTemplate = true)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ object Scanners {
* - In Scala 2: Only `{` is treated as continuing, irrespective of indentation.
* But this is in fact handled by Parser.argumentStart which skips a NEWLINE,
* so we always assume false here.
* - In Scala 3: Only indented statements are treated as continuing, as long as
* - In Scala 3: Indented statements are treated as continuing, as long as
* they start with `(`, `[` or `{`, or the last statement ends in a `return`.
* The Scala 2 rules apply under source `3.0-migration` or under `-no-indent`.
* The Scala 2 rules apply under source `3.0-migration` or under `-no-indent`.
*/
inline def isContinuing =
lastWidth < nextWidth
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait TraceSyntax:
apply(question, printer, {
val showOp: T => String = inline if show == true then
val showT = summonInline[Show[T]]
{
locally {
given Show[T] = showT
t => i"$t"
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else
errorTree(tree, em"Missing arguments for $methodStr")
case _ => tryInsertApplyOrImplicit(tree, pt, locked) {
errorTree(tree, MethodDoesNotTakeParameters(tree))
errorTree(tree, MethodDoesNotTakeParameters(tree), tree.srcPos.endPos)
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class CompilationTests {
compileFile("tests/neg-custom-args/i3246.scala", scala2CompatMode),
compileFile("tests/neg-custom-args/overrideClass.scala", scala2CompatMode),
compileFile("tests/neg-custom-args/ovlazy.scala", scala2CompatMode.and("-Xfatal-warnings")),
compileFile("tests/neg-custom-args/newline-braces.scala", scala2CompatMode.and("-Xfatal-warnings")),
compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.andLanguageFeature("noAutoTupling")),
compileFile("tests/neg-custom-args/i1650.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes),
Expand Down
6 changes: 0 additions & 6 deletions tests/neg-custom-args/newline-braces.scala

This file was deleted.

6 changes: 3 additions & 3 deletions tests/neg/bad-unapplies.check
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
| D cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method
|
| longer explanation available when compiling with `-explain`
-- [E050] Type Error: tests/neg/bad-unapplies.scala:25:9 ---------------------------------------------------------------
-- [E050] Type Error: tests/neg/bad-unapplies.scala:25:10 --------------------------------------------------------------
25 | case E("2") => // error (value unapply in object E does not take parameters)
| ^
| value unapply in object E does not take parameters
| ^
| value unapply in object E does not take parameters
|
| longer explanation available when compiling with `-explain`
-- [E107] Syntax Error: tests/neg/bad-unapplies.scala:26:10 ------------------------------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions tests/neg/i10857.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- [E008] Not Found Error: tests/neg/i10857.scala:33:17 ----------------------------------------------------------------
33 | println(Module.valueOf("Red")) // error: value valueOf is not a member
| ^^^^^^^^^^^^^^
| value valueOf is not a member of object Module
-- [E008] Not Found Error: tests/neg/i10857.scala:36:21 ----------------------------------------------------------------
36 | println(new Module.GivenBar()) // error: type GivenBar is not a member
| ^^^^^^^^^^^^^^^
| type GivenBar is not a member of object Module - did you mean Module.Givens.type?
-- [E050] Type Error: tests/neg/i10857.scala:37:25 ---------------------------------------------------------------------
37 | println(Module.GivenBar(23)) // error: method GivenBar does not take parameters
| ^
| given instance GivenBar in object Module does not take parameters
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg/i10857.scala:41:24 ------------------------------------------------------------
41 | println(Module.Member("?")(23)) // error: Found: ("?" : String) Required: Int // error: method Member in object Module does not take more parameters
| ^^^
| Found: ("?" : String)
| Required: Int
|
| longer explanation available when compiling with `-explain`
-- [E050] Type Error: tests/neg/i10857.scala:41:28 ---------------------------------------------------------------------
41 | println(Module.Member("?")(23)) // error: Found: ("?" : String) Required: Int // error: method Member in object Module does not take more parameters
| ^
| method Member in object Module does not take more parameters
|
| longer explanation available when compiling with `-explain`
-- [E172] Type Error: tests/neg/i10857.scala:42:28 ---------------------------------------------------------------------
42 | println(summon[Module.Baz]) // error: no implicit argument of type Module.Baz was found
| ^
| No given instance of type Module.Baz was found for parameter x of method summon in object Predef
2 changes: 1 addition & 1 deletion tests/neg/i10857.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Module:

println(new Module.Member())
println(Module.Member(23))
println(Module.Member("?")(23)) // error: Found: ("?" : String) Required: Int
println(Module.Member("?")(23)) // error: Found: ("?" : String) Required: Int // error: method Member in object Module does not take more parameters
println(summon[Module.Baz]) // error: no implicit argument of type Module.Baz was found

println(summon[Module.Qux])
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i12554a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Test {

def i: Unit = {
f("Foo")
{} // ok, error in Scala 2
{} // error, error in Scala 2
}

def j: Int = {
Expand Down
6 changes: 3 additions & 3 deletions tests/neg/i14818.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
| ^^^^^^
| no eligible member B at M
| M.B cannot be exported because it clashes with another export in the same export clause
-- [E050] Type Error: tests/neg/i14818.scala:16:10 ---------------------------------------------------------------------
-- [E050] Type Error: tests/neg/i14818.scala:16:11 ---------------------------------------------------------------------
16 | val x = b(1) // error
| ^
| method b in object T3 does not take parameters
| ^
| method b in object T3 does not take parameters
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i14818.scala:19:22 ---------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/neg/i1707.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object DepBug {
import d.*
a m (b)
}

{
import dep.*
a m (b) // error: not found: a
Expand Down
6 changes: 3 additions & 3 deletions tests/neg/i9437.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E050] Type Error: tests/neg/i9437.scala:7:10 -----------------------------------------------------------------------
-- [E050] Type Error: tests/neg/i9437.scala:7:14 -----------------------------------------------------------------------
7 | println(x.f1()) // error
| ^^^^
| method selectDynamic in trait Selectable does not take parameters
| ^
| method selectDynamic in trait Selectable does not take parameters
|
| longer explanation available when compiling with `-explain`
13 changes: 13 additions & 0 deletions tests/new/i16760.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object Test {
def main(args: Array[String]): Unit = {
def process(arg: Int)(block: => Unit): Int = arg
val x = process(1)
{
}
println(x)
val y = process(2)
( ()
)
println(y)
}
}
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait TraceSyntax:
apply(question, printer, {
val showOp: T => String = inline if show == true then
val showT = summonInline[Show[T]]
{
locally {
given Show[T] = showT
t => i"$t"
}
Expand Down
1 change: 1 addition & 0 deletions tests/pos/indented-parens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ def f(x: Int)
(2)
+ f(1)
{2}

{ println(x) }