Skip to content

Commit 44c8333

Browse files
authored
Merge pull request #239 from scala/backport-lts-3.3-22477
Backport "Correctly detect colon lambda eol indent for optional brace of argument" to 3.3 LTS
2 parents 5943ed6 + e39adec commit 44c8333

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

tests/pos/i22193.scala

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 test() =
7+
8+
fn2(arg = "blue sleeps faster than tuesday", arg2 = "the quick brown fox jumped over the lazy dog"): env =>
9+
val x = env
10+
println(x)
11+
12+
// doesn't compile
13+
fn2(
14+
arg = "blue sleeps faster than tuesday",
15+
arg2 = "the quick brown fox jumped over the lazy dog"): env =>
16+
val x = env
17+
println(x)
18+
19+
fn2(
20+
arg = "blue sleeps faster than tuesday",
21+
arg2 = "the quick brown fox jumped over the lazy dog"): env =>
22+
val x = env
23+
println(x)
24+
25+
fn2(
26+
arg = "blue sleeps faster than tuesday",
27+
arg2 = "the quick brown fox jumped over the lazy dog"): env =>
28+
val x = env
29+
println(x)
30+
31+
// does compile
32+
fn2(
33+
arg = "blue sleeps faster than tuesday",
34+
arg2 = "the quick brown fox jumped over the lazy dog"):
35+
env =>
36+
val x = env
37+
println(x)
38+
39+
// does compile
40+
fn2(
41+
arg = "blue sleeps faster than tuesday",
42+
arg2 = "the quick brown fox jumped over the lazy dog"
43+
): env =>
44+
val x = env
45+
println(x)
46+
47+
fn2(
48+
arg = "blue sleeps faster than tuesday",
49+
arg2 = "the quick brown fox jumped over the lazy dog"
50+
): env =>
51+
val x = env
52+
println(x)
53+
54+
fn3(
55+
arg = "blue sleeps faster than tuesday",
56+
arg2 = "the quick brown fox jumped over the lazy dog"):
57+
val x = "Hello"
58+
println(x)
59+
60+
fn3(
61+
arg = "blue sleeps faster than tuesday",
62+
arg2 = "the quick brown fox jumped over the lazy dog"):
63+
val x = "Hello"
64+
println(x)
65+
66+
fn3( // arg at 3, body at 3
67+
arg = "blue sleeps faster than tuesday",
68+
arg2 = "the quick brown fox jumped over the lazy dog"):
69+
val x = "Hello"
70+
println(x)
71+
72+
fn3( // arg at 3, body at 1: not sure if sig indent of 1 is allowed, saw some comments from odersky
73+
arg = "blue sleeps faster than tuesday",
74+
arg2 = "the quick brown fox jumped over the lazy dog"):
75+
val x = "Hello"
76+
println(x)
77+
78+
fn3( // arg at 3, body at 2: even if sig indent of 1 is not allowed, body is at fn3+2, not arg2-1
79+
arg = "blue sleeps faster than tuesday",
80+
arg2 = "the quick brown fox jumped over the lazy dog"):
81+
val x = "Hello"
82+
println(x)
83+
84+
fn3( // arg at 3, body at 4
85+
arg = "blue sleeps faster than tuesday",
86+
arg2 = "the quick brown fox jumped over the lazy dog"):
87+
val x = "Hello"
88+
println(x)
89+
90+
// don't turn innocent empty cases into functions
91+
def regress(x: Int) =
92+
x match
93+
case 42 =>
94+
case _ =>
95+
96+
// previously lookahead calculated indent width at the colon
97+
def k(xs: List[Int]) =
98+
xs.foldLeft(
99+
0)
100+
: (acc, x) =>
101+
acc + x
102+
103+
def `test kit`(xs: List[Int]): Unit =
104+
def addOne(i: Int): Int = i + 1
105+
def isPositive(i: Int): Boolean = i > 0
106+
// doesn't compile but would be nice
107+
// first body is indented "twice", or, rather, first outdent establishes an intermediate indentation level
108+
xs.map: x =>
109+
x + 1
110+
.filter: x =>
111+
x > 0
112+
xs.map:
113+
addOne
114+
.filter:
115+
isPositive
116+
117+
// does compile
118+
xs
119+
.map: x =>
120+
x + 1
121+
.filter: x =>
122+
x > 0
123+
124+
// does compile but doesn't look good, at least, to some people
125+
xs.map: x =>
126+
x + 1
127+
.filter: x =>
128+
x > 0
129+
130+
def `tested kit`(xs: List[Int]): Unit =
131+
{
132+
def addOne(i: Int): Int = i.+(1)
133+
def isPositive(i: Int): Boolean = i.>(0)
134+
xs.map[Int]((x: Int) => x.+(1)).filter((x: Int) => x.>(0))
135+
xs.map[Int]((i: Int) => addOne(i)).filter((i: Int) => isPositive(i))
136+
xs.map[Int]((x: Int) => x.+(1)).filter((x: Int) => x.>(0))
137+
{
138+
xs.map[Int]((x: Int) => x.+(1)).filter((x: Int) => x.>(0))
139+
()
140+
}
141+
}

0 commit comments

Comments
 (0)