Skip to content

Commit d9c3bd5

Browse files
authored
Merge pull request scala#5838 from som-snytt/issue/2458
SI-2458 Make spec example live test
2 parents 1ef37f0 + ed63344 commit d9c3bd5

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

test/files/neg/ambiguous-same.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ambiguous-same.scala:13: error: reference to x is ambiguous;
2+
it is both defined in object X and imported subsequently by
3+
import X.x
4+
x
5+
^
6+
one error found

test/files/neg/ambiguous-same.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// When faced with ambiguities between imports,
3+
// an attempt is made to see if the imports intend
4+
// identical types.
5+
//
6+
// Here, no attempt is made to notice that x
7+
// names the same thing.
8+
//
9+
object X {
10+
val x = 42
11+
def f = {
12+
import X.x
13+
x
14+
}
15+
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
P_2.scala:14: error: reference to x is ambiguous;
2-
it is both defined in object C and imported subsequently by
3-
import Q.X._
4-
println("L14: "+x) // reference to 'x' is ambiguous here
5-
^
6-
P_2.scala:19: error: reference to y is ambiguous;
1+
P_2.scala:15: error: reference to x is ambiguous;
2+
it is both defined in value <local Y> and imported subsequently by
3+
import q.X._
4+
println(s"L15: $x") // reference to `x' is ambiguous here
5+
^
6+
P_2.scala:21: error: reference to y is ambiguous;
77
it is imported twice in the same scope by
8-
import P.X._
8+
import p.X._
99
and import X.y
10-
println("L19: "+y) // reference to 'y' is ambiguous here
11-
^
10+
println(s"L21: $y") // reference to `y' is ambiguous here
11+
^
1212
two errors found
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package P {
2-
object X { val x = 1; val y = 2; }
1+
package p {
2+
object X { val x = 1; val y = 2 }
33
}
4-
package Q {
5-
object X { val x = true; val y = "" }
4+
5+
package q {
6+
object X { val x = true; val y = false }
67
}
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
package P { // 'X' bound by package clause
2-
import Console._ // 'println' bound by wildcard import
3-
object A {
4-
println("L4: "+X) // 'X' refers to 'P.X' here
5-
object B {
6-
import Q._ // 'X' bound by wildcard import
7-
println("L7: "+X) // 'X' refers to 'Q.X' here
8-
import X._ // 'x' and 'y' bound by wildcard import
9-
println("L8: "+x) // 'x' refers to 'Q.X.x' here
10-
object C {
11-
val x = 3 // 'x' bound by local definition
12-
println("L12: "+x); // 'x' refers to constant '3' here
13-
{ import Q.X._ // 'x' and 'y' bound by wildcard
14-
println("L14: "+x) // reference to 'x' is ambiguous here
15-
import X.y // 'y' bound by explicit import
16-
println("L16: "+y); // 'y' refers to 'Q.X.y' here
17-
{ val x = "abc" // 'x' bound by local definition
18-
import P.X._ // 'x' and 'y' bound by wildcard
19-
println("L19: "+y) // reference to 'y' is ambiguous here
20-
println("L20: "+x) // 'x' refers to string ''abc'' here
1+
package p { // `X' bound by package clause
2+
import Console._ // `println' bound by wildcard import
3+
object Y {
4+
println(s"L4: $X") // `X' refers to `p.X' here
5+
locally {
6+
import q._ // `X' bound by wildcard import
7+
println(s"L7: $X") // `X' refers to `q.X' here
8+
import X._ // `x' and `y' bound by wildcard import
9+
println(s"L9: $x") // `x' refers to `q.X.x' here
10+
locally {
11+
val x = 3 // `x' bound by local definition
12+
println(s"L12: $x") // `x' refers to constant `3' here
13+
locally {
14+
import q.X._ // `x' and `y' bound by wildcard import
15+
println(s"L15: $x") // reference to `x' is ambiguous here
16+
import X.y // `y' bound by explicit import
17+
println(s"L17: $y") // `y' refers to `q.X.y' here
18+
locally {
19+
val x = "abc" // `x' bound by local definition
20+
import p.X._ // `x' and `y' bound by wildcard import
21+
println(s"L21: $y") // reference to `y' is ambiguous here
22+
println(s"L22: $x") // `x' refers to string "abc" here
2123
}}}}}}
24+

0 commit comments

Comments
 (0)