Skip to content

Fix #1857: Allow lower bounds to influence implicit search #3921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,7 @@ trait ImplicitRunInfo { self: Run =>
}
tp.classSymbols(liftingCtx) foreach addClassScope
case _ =>
// We exclude lower bounds to conform to SLS 7.2:
// "The parts of a type T are: [...] if T is an abstract type, the parts of its upper bound"
for (part <- tp.namedPartsWith(_.isType, excludeLowerBounds = true))
comps ++= iscopeRefs(part)
for (part <- tp.namedPartsWith(_.isType)) comps ++= iscopeRefs(part)
}
comps
}
Expand Down
38 changes: 38 additions & 0 deletions tests/pos/i1857.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package commandeer


trait CommandeerDSL[Host] {
trait Operation[T]
type Op[T] <: Operation[T]
}

object CommandeerDSL {
def apply[Host, DSL <: CommandeerDSL[Host]](host: Host)(implicit dsl: DSL): DSL = dsl
}

trait Foo {
def bar(a: String, b: Int): Double
}

object Foo {
implicit val fooDSL: FooDSL = new FooDSL {}
}

trait FooDSL extends CommandeerDSL[Foo] {
sealed trait FooOperation[T] extends Operation[T]
type Op[T] = FooOperation[T]

case class Bar(a: String, b: Int) extends FooOperation[Double]
}

object RunMe {
//import Foo._
def main(args: Array[String]): Unit = {
println("Hi Mum")

val kevin = CommandeerDSL(null.asInstanceOf[Foo])
println(s"Found DSL for Foo: $kevin")
val bar = kevin.Bar("bob", 3)
println(s"Made a bar: $bar")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Test {
def get1(implicit lf: List[_ <: Bar]) = {}
def get2(implicit lf: List[_ >: Bar]) = {}

get1 // works
get2 // error
get1
get2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll note that this line doesn't compile with scalac, so scalac interpretation of SLS 7.2 seems to match what I had in mind.

}