Skip to content

Commit f52186d

Browse files
committed
chore: Add changes from missing commits
1 parent 6acb0eb commit f52186d

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import config.Feature
3333
import config.Feature.{sourceVersion, migrateTo3, globalOnlyImports}
3434
import config.SourceVersion.*
3535
import config.SourceVersion
36+
import dotty.tools.dotc.util.chaining.*
3637

3738
object Parsers {
3839

@@ -1020,10 +1021,11 @@ object Parsers {
10201021
*/
10211022
def followingIsLambdaAfterColon(): Boolean =
10221023
val lookahead = in.LookaheadScanner(allowIndent = true)
1024+
.tap(_.currentRegion.knownWidth = in.currentRegion.indentWidth)
10231025
def isArrowIndent() =
10241026
lookahead.isArrow
10251027
&& {
1026-
lookahead.nextToken()
1028+
lookahead.observeArrowIndented()
10271029
lookahead.token == INDENT || lookahead.token == EOF
10281030
}
10291031
lookahead.nextToken()

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ object Scanners {
636636
insert(OUTDENT, offset)
637637
else if r.isInstanceOf[InBraces] && !closingRegionTokens.contains(token) then
638638
report.warning("Line is indented too far to the left, or a `}` is missing", sourcePos())
639-
640639
else if lastWidth < nextWidth
641640
|| lastWidth == nextWidth && (lastToken == MATCH || lastToken == CATCH) && token == CASE then
642641
if canStartIndentTokens.contains(lastToken) then
@@ -656,7 +655,7 @@ object Scanners {
656655
def spaceTabMismatchMsg(lastWidth: IndentWidth, nextWidth: IndentWidth): Message =
657656
em"""Incompatible combinations of tabs and spaces in indentation prefixes.
658657
|Previous indent : $lastWidth
659-
|Latest indent : $nextWidth"""
658+
|Latest indent : $nextWidth"""
660659

661660
def observeColonEOL(inTemplate: Boolean): Unit =
662661
val enabled =
@@ -670,6 +669,23 @@ object Scanners {
670669
reset()
671670
if atEOL then token = COLONeol
672671

672+
// consume => and insert <indent> if applicable. Used to detect colon arrow: x =>
673+
def observeArrowIndented(): Unit =
674+
if isArrow && indentSyntax then
675+
peekAhead()
676+
val atEOL = isAfterLineEnd
677+
val atEOF = token == EOF
678+
reset()
679+
if atEOF then
680+
token = EOF
681+
else if atEOL then
682+
val nextWidth = indentWidth(next.offset)
683+
val lastWidth = currentRegion.indentWidth
684+
if lastWidth < nextWidth then
685+
currentRegion = Indented(nextWidth, COLONeol, currentRegion)
686+
offset = next.offset
687+
token = INDENT
688+
673689
def observeIndented(): Unit =
674690
if indentSyntax && isNewLine then
675691
val nextWidth = indentWidth(next.offset)
@@ -1098,7 +1114,7 @@ object Scanners {
10981114
reset()
10991115
next
11001116

1101-
class LookaheadScanner(val allowIndent: Boolean = false) extends Scanner(source, offset, allowIndent = allowIndent) {
1117+
class LookaheadScanner(allowIndent: Boolean = false) extends Scanner(source, offset, allowIndent = allowIndent) {
11021118
override protected def initialCharBufferSize = 8
11031119
override def languageImportContext = Scanner.this.languageImportContext
11041120
}
@@ -1650,7 +1666,7 @@ object Scanners {
16501666
case class InCase(outer: Region) extends Region(OUTDENT)
16511667

16521668
/** A class describing an indentation region.
1653-
* @param width The principal indendation width
1669+
* @param width The principal indentation width
16541670
* @param prefix The token before the initial <indent> of the region
16551671
*/
16561672
case class Indented(width: IndentWidth, prefix: Token, outer: Region | Null) extends Region(OUTDENT):

tests/neg/i22193.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
def fn2(arg: String, arg2: String)(f: String => Unit): Unit = f(arg)
3+
4+
def fn3(arg: String, arg2: String)(f: => Unit): Unit = f
5+
6+
def test1() =
7+
8+
// ok baseline
9+
fn2(arg = "blue sleeps faster than tuesday", arg2 = "the quick brown fox jumped over the lazy dog"): env =>
10+
val x = env
11+
println(x)
12+
13+
fn2( // error not a legal formal parameter for a function literal
14+
arg = "blue sleeps faster than tuesday",
15+
arg2 = "the quick brown fox jumped over the lazy dog"): env =>
16+
val x = env // error
17+
println(x)
18+
19+
fn2(
20+
arg = "blue sleeps faster than tuesday",
21+
arg2 = "the quick brown fox jumped over the lazy dog"):
22+
env => // error indented definitions expected, identifier env found
23+
val x = env
24+
println(x)
25+
26+
def test2() =
27+
28+
fn3( // error missing argument list for value of type (=> Unit) => Unit
29+
arg = "blue sleeps faster than tuesday",
30+
arg2 = "the quick brown fox jumped over the lazy dog"):
31+
val x = "Hello" // error
32+
println(x) // error

0 commit comments

Comments
 (0)