Skip to content
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
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,14 @@ object Parsers {
ts.toList
else leading :: Nil

def maybeNamed(op: () => Tree): () => Tree = () =>
def maybeNamed(location: Location, op: () => Tree): () => Tree = () =>
if isIdent && in.lookahead.token == EQUALS && sourceVersion.enablesNamedTuples then
atSpan(in.offset):
val name = ident()
in.nextToken()
if location.inPattern && in.token == INDENT then
in.currentRegion = in.currentRegion.outer
in.nextToken()
NamedArg(name, op())
else op()

Expand Down Expand Up @@ -2958,7 +2961,7 @@ object Parsers {
if isErased then isFormalParams = true
if isFormalParams then binding(Modifiers())
else
val t = maybeNamed(exprInParens)()
val t = maybeNamed(Location.InParens, exprInParens)()
if t.isInstanceOf[ValDef] then isFormalParams = true
t
commaSeparatedRest(exprOrBinding(), exprOrBinding)
Expand Down Expand Up @@ -3411,8 +3414,8 @@ object Parsers {
* | NamedPattern {‘,’ NamedPattern}
* NamedPattern ::= id '=' Pattern
*/
def patterns(location: Location = Location.InPattern): List[Tree] =
commaSeparated(maybeNamed(() => pattern(location)))
def patterns(location: Location = Location.InPattern): List[Tree] = // default used from Markup
commaSeparated(maybeNamed(location, () => pattern(location)))
// check that patterns are all named or all unnamed is done at desugaring

def patternsOpt(location: Location = Location.InPattern): List[Tree] =
Expand Down
19 changes: 16 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,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
Expand Down Expand Up @@ -765,7 +771,14 @@ object Scanners {
case _ => false
currentRegion match
case r: Indented if isEnclosedInParens(r.outer) =>
insert(OUTDENT, offset)
// For region prefix COLONeol, only OUTDENT if COMMA at EOL
if r.prefix == COLONeol then
val lookahead = LookaheadScanner()
lookahead.nextToken()
if lookahead.isAfterLineEnd then
insert(OUTDENT, offset)
else
insert(OUTDENT, offset)
case _ =>
peekAhead()
if isAfterLineEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CompletionExtensionSuite extends BaseCompletionSuite:

@Test def `filter-by-type-old` =
check(
"""|package example
"""|package example
|
|object enrichments:
| implicit class A(num: Int):
Expand All @@ -99,7 +99,6 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
"""|identity: String (implicit)
|""".stripMargin, // identity2 won't be available
filter = _.contains("(implicit)")

)

@Test def `filter-by-type-subtype` =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
| **/
|}
|""".stripMargin,
"",
"",
includeCommitCharacter = true
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ class CompletionSuite extends BaseCompletionSuite:
| val t: TT@@
|}
|""".stripMargin,
"TTT[A <: Int] = List[A]"
"TTT[A <: Int] = List[A]"
)

@Test def `type-lambda` =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class HoverDocSuite extends BaseHoverSuite:

@Test def `doc` =
check(
"""object a {
| <<java.util.Collections.empty@@List[Int]>>
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|java.util.List[Int]
|```
|**Symbol signature**:
|```scala
|final def emptyList[T](): java.util.List[T]
|```
|Found documentation for java/util/Collections#emptyList().
|""".stripMargin,
"""|object a {
| <<java.util.Collections.empty@@List[Int]>>
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|java.util.List[Int]
|```
|**Symbol signature**:
|```scala
|final def emptyList[T](): java.util.List[T]
|```
|Found documentation for java/util/Collections#emptyList().
|""".stripMargin,
)

@Test def `doc-parent` =
Expand All @@ -47,7 +47,6 @@ class HoverDocSuite extends BaseHoverSuite:
|```
|Found documentation for scala/collection/LinearSeqOps#headOption().
|""".stripMargin,

)

@Test def `java-method` =
Expand All @@ -61,7 +60,7 @@ class HoverDocSuite extends BaseHoverSuite:
|```
|Found documentation for java/lang/String#substring().
|""".stripMargin
)
)

@Test def `object` =
check(
Expand Down
20 changes: 10 additions & 10 deletions scaladoc/test/dotty/tools/scaladoc/site/TemplateFileTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,26 @@ class TemplateFileTests:
testTemplate(
"""# Hello {{ msg }}!""",
ext = "md"
) { t =>
): t =>
assertEquals(
"""<section id="hello-there">
|<h1 class="h500"><a href="#hello-there" class="anchor"></a>Hello there!</h1>
|</section>""".stripMargin,
t.resolveInner(RenderingContext(Map("msg" -> "there"))).code.trim())
}
|<h1 class="h500"><a href="#hello-there" class="anchor"></a>Hello there!</h1>
|</section>""".stripMargin,
t.resolveInner(RenderingContext(Map("msg" -> "there"))).code.trim()
)

@Test
def mixedTemplates() : Unit =
testTemplate(
"""# Hello {{ msg }}!""",
ext = "md"
) { t =>
): t =>
assertEquals(
"""<section id="hello-there2">
|<h1 class="h500"><a href="#hello-there2" class="anchor"></a>Hello there2!</h1>
|</section>""".stripMargin,
t.resolveInner(RenderingContext(Map("msg" -> "there2"))).code.trim())
}
|<h1 class="h500"><a href="#hello-there2" class="anchor"></a>Hello there2!</h1>
|</section>""".stripMargin,
t.resolveInner(RenderingContext(Map("msg" -> "there2"))).code.trim()
)

@Test
def htmlOnly(): Unit =
Expand Down
30 changes: 30 additions & 0 deletions tests/neg/i22527.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

//rule of thumb is COLONeol was at EOL, so COMMA must be at EOL
def test: Unit =
assert(
identity:
true, "ok" // error end of statement expected but ',' found
)

def callme[A](x: => A, msg: String) = try x.toString catch case t: RuntimeException => msg

// not all indented regions require COMMA at EOL for OUTDENT
def orElse(x: Int): Unit =
callme(
if x > 0 then
class X extends AnyRef, Serializable // error Not found: Serializable - did you mean Specializable?
true // error ',' or ')' expected, but 'true' found
else
false, "fail")

def g: Unit =
identity(
x =
class X extends AnyRef, Serializable // error
27 // error
)

def onlyIf(x: Int): Unit =
callme(
if (x > 0)
true, "fail") // error syntax is broken after old-style conditional
6 changes: 2 additions & 4 deletions tests/neg/syntax-error-recovery.check
Original file line number Diff line number Diff line change
Expand Up @@ -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
77 changes: 77 additions & 0 deletions tests/pos/i22527.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

//> using options -Werror

import annotation.*

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")

@nowarn("msg=Unit")
def onlyIf(x: Int): Unit =
callme(
if (x > 0) then // then syntax required
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,
z,
)
)

object `arrow eol`:
def f(g: Int => Int, i: Int): Int = g(i)
def g(map: Int => Int): Int => Int = map
def test =
f(
g: x =>
x + 1, 42
)
28 changes: 28 additions & 0 deletions tests/pos/i24474.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
case class Foo(arg1: Int, arg2: Int)
case class Bar(arg1: Int, arg2: Option[Int])

object OK:
Foo(1, 2) match
case Foo(arg1 =
5
) =>

object Test:
Foo(1, 2) match
case Foo(arg1 =
5 // was: error: pattern expected
) =>

object Nest:
Bar(1, Option(2)) match
case Bar(arg2 =
Some(value =
42
)
) =>

object Detupled:
(fst = 1, snd = 2) match
case (fst =
5
) =>
22 changes: 22 additions & 0 deletions tests/warn/i22527.check
Original file line number Diff line number Diff line change
@@ -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`
Loading
Loading