Skip to content

Commit 6df641e

Browse files
committed
Test inline method returning match type
1 parent 7c3ddc3 commit 6df641e

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

compiler/test/dotc/pos-test-pickling.excludelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ named-tuples1.scala
7272
i20897.scala
7373
i20512.scala
7474
i22645b.scala
75+
i17210.scala
7576

7677
# Opaque type
7778
i5720.scala

tests/neg/i17210.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
object BugReport:
3+
trait Executor
4+
trait Updatable[+A]
5+
6+
def run(task: Executor ?=> Unit): Unit = ()
7+
def tupledFunction(a: Int, b: Int): Unit = ()
8+
def tupledSequence(f: ((Updatable[Int], Updatable[Int])) => Unit): Unit = ()
9+
10+
type UpdatableMap[T <: Tuple] = T match
11+
case EmptyTuple => EmptyTuple
12+
case h *: t => Updatable[h] *: UpdatableMap[t]
13+
// eliminate the match type
14+
type xUpdatableMap[_] = (Updatable[Int], Updatable[Int])
15+
16+
// so that expected type is satisfied, avoid eta-expansion and subsequent error
17+
def liftAsTupledInThreads[A <: Tuple](f: A => Unit)(using e: Executor): UpdatableMap[A] => Unit = _ => ()
18+
// eliminate eta-expansion where the partial application returns a context function
19+
def xliftAsTupledInThreads[A <: Tuple](f: A => Unit): Executor ?=> UpdatableMap[A] => Unit = _ => ()
20+
21+
run:
22+
tupledSequence(liftAsTupledInThreads(tupledFunction.tupled)) // error
23+
24+
run:
25+
val lifted = liftAsTupledInThreads(tupledFunction.tupled)
26+
// the expected type induces the symptom
27+
//val lifted: ((Updatable[Int], Updatable[Int])) => Unit = liftAsTupledInThreads(tupledFunction.tupled)
28+
tupledSequence(lifted)

tests/pos/i17210.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
object BugReport:
3+
trait Executor
4+
trait Updatable[+A]
5+
6+
def run(task: Executor ?=> Unit): Unit = ()
7+
def tupledFunction(a: Int, b: Int): Unit = ()
8+
def tupledSequence(f: ((Updatable[Int], Updatable[Int])) => Unit): Unit = ()
9+
10+
type UpdatableMap[T <: Tuple] = T match
11+
case EmptyTuple => EmptyTuple
12+
case h *: t => Updatable[h] *: UpdatableMap[t]
13+
// eliminate the match type
14+
type xUpdatableMap[_] = (Updatable[Int], Updatable[Int])
15+
16+
// so that expected type is satisfied, avoid eta-expansion and subsequent error
17+
transparent inline // presumably allows match type "expansion" before adaptation
18+
def liftAsTupledInThreads[A <: Tuple](f: A => Unit)(using e: Executor): UpdatableMap[A] => Unit = _ => ()
19+
// eliminate eta-expansion where the partial application returns a context function
20+
def xliftAsTupledInThreads[A <: Tuple](f: A => Unit): Executor ?=> UpdatableMap[A] => Unit = _ => ()
21+
22+
run:
23+
tupledSequence(liftAsTupledInThreads(tupledFunction.tupled)) // was error
24+
25+
run:
26+
val lifted = liftAsTupledInThreads(tupledFunction.tupled)
27+
// the expected type induces the symptom
28+
//val lifted: ((Updatable[Int], Updatable[Int])) => Unit = liftAsTupledInThreads(tupledFunction.tupled)
29+
tupledSequence(lifted)
30+
31+
object BugReport2:
32+
trait Executor
33+
trait Updatable[+A]
34+
35+
def run(task: Executor ?=> Unit): Unit = ()
36+
def function(a: Int): Unit = ()
37+
def normalSequence(f: Updatable[Int] => Unit): Unit = ()
38+
39+
def liftInThreads[A](f: A => Unit)(using e: Executor): Updatable[A] => Unit = _ => ()
40+
41+
run:
42+
normalSequence(liftInThreads(function))

0 commit comments

Comments
 (0)