8000 Add Regression test for Scala Bug 7131 · scala/scala@39f0192 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39f0192

Browse files
committed
Add Regression test for Scala Bug 7131
Scala Bug 7131 reported a compiler crash at the typer phase. Testing recently, that same program no longer crashes the compiler. This commit adds the program in question, to watch for regressions.
1 parent 1f76b24 commit 39f0192

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

test/files/neg/t7131.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t7131.scala:21: error: type mismatch;
2+
found : Iterable[U]
3+
required: That
4+
Note: implicit method convertToSimpleMappable is not applicable here because it comes after the application point and it lacks an explicit result type
5+
x.value.map(f)
6+
^
7+
one error found

test/files/neg/t7131.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-language:higherKinds -language:reflectiveCalls -language:implicitConversions

test/files/neg/t7131.scala

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import collection.generic.CanBuildFrom
2+
3+
// leaving out the observable part
4+
trait ObservableValue[-T] {
5+
def value: T
6+
}
7+
8+
object ObservableValue {
9+
10+
//this works as is
11+
implicit class SimpleMappable[T](x: ObservableValue[T]) {
12+
def map[U](f: T => U) = new ObservableValue[U] {
13+
def value = f(x.value)
14+
}
15+
}
16+
17+
class TraversableMappable[T, Container[X] <: Traversable[X]](x: ObservableValue[Container[T]]) {
18+
19+
def map[U, That](f: T => U)(implicit bf: CanBuildFrom[Traversable[T], U, That]): ObservableValue[That] = new ObservableValue[That] {
20+
def value: That = {
21+
x.value.map(f)
22+
}
23+
}
24+
25+
}
26+
27+
//for some reason using an implicit class does not work
28+
implicit def convertToTraversableMappable[T, Container[X] <: Traversable[X]](x: ObservableValue[Container[T]]) =
29+
new TraversableMappable(x)
30+
31+
type HasMap[T, That[_]] = {
32+
def map[U](f: T => U): That[U]
33+
}
34+
35+
class NestedMappable[T, Container[X] <: HasMap[X, Container]](x: ObservableValue[Container[T]]) {
36+
37+
def map[U](f: T => U): ObservableValue[Container[U]] = new ObservableValue[Container[U]] {
38+
def value: Container[U] = x.value.map(f)
39+
}
40+
}
41+
42+
//for some reason using an implicit class does not work
43+
implicit def convertToSimpleMappable[T, Container[X] <: ObservableValue.HasMap[X, Container]](x: ObservableValue[Container[T]]) =
44+
new NestedMappable(x)
45+
46+
}
47+
48+
object Main extends App {
49+
50+
class TestCase extends ObservableValue[Int] {
51+
var value: Int = 0
52+
}
53+
54+
val x = new TestCase
55+
56+
val r = x.map(_ + 1)
57+
58+
println(r.value) //1
59+
60+
x.value = 42
61+
62+
println(r.value) //43
63+
64+
65+
class TestCase1 extends ObservableValue[Option[Int]] {
66+
var value: Option[Int] = None
67+
}
68+
69+
val x1 = new TestCase1
70+
71+
val r1 = x1 map ((x: Int) => x + 1)
72+
73+
println(r1.value) //None
74+
75+
x1.value = Some(3)
76+
77+
println(r1.value) //Some(4)
78+
79+
class TestCase2 extends ObservableValue[List[Int]] {
80+
var value: List[Int] = List()
81+
}
82+
83+
val y = new TestCase2
84+
85+
val q = y map (_ + 1)
86+
87+
println(q.value) //List()
88+
89+
y.value = List(3, 4)
90+
91+
println(q.value) //List(4, 5)
92+
93+
}

0 commit comments

Comments
 (0)
0