Skip to content

Commit 0efa171

Browse files
committed
Don't add lower bounds of abstract types to the implicit scope
As the spec[1] says: "The parts of a type T are [...] if T is an abstract type, the parts of its upper bound;" [1]: http://www.scala-lang.org/files/archive/spec/2.11/07-implicits.html#implicit-parameters
1 parent b823132 commit 0efa171

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,8 @@ object Types {
31183118
apply(foldOver(maybeAdd(x, tp), tp), tp.underlying)
31193119
case tp: TypeRef =>
31203120
foldOver(maybeAdd(x, tp), tp)
3121+
case TypeBounds(_, hi) =>
3122+
apply(x, hi)
31213123
case tp: ThisType =>
31223124
apply(x, tp.underlying)
31233125
case tp: ConstantType =>

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class tests extends CompilerTest {
144144
@Test def neg_traitParamsTyper = compileFile(negDir, "traitParamsTyper", xerrors = 5)
145145
@Test def neg_traitParamsMixin = compileFile(negDir, "traitParamsMixin", xerrors = 2)
146146
@Test def neg_firstError = compileFile(negDir, "firstError", xerrors = 3)
147+
@Test def neg_implicitLowerBound = compileFile(negDir, "implicit-lower-bound", xerrors = 1)
147148

148149
@Test def run_all = runFiles(runDir)
149150

tests/neg/implicit-lower-bound.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Foo
2+
3+
class Bar extends Foo
4+
object Bar {
5+
implicit val listbar: List[Bar] = ???
6+
}
7+
8+
class Test {
9+
def get1(implicit lf: List[_ <: Bar]) = {}
10+
def get2(implicit lf: List[_ >: Bar]) = {}
11+
12+
get1 // works
13+
get2 // error
14+
}

0 commit comments

Comments
 (0)