Skip to content

Commit

Permalink
Support multiple implicit parameter lists
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Mar 28, 2019
1 parent 8b8d813 commit cd9a29f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Expand Up @@ -1378,11 +1378,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
}

/** Drop any implicit parameter section */
def stripImplicit(tp: Type, weight: Int): Type = tp match {
def stripImplicit(tp: Type): Type = tp match {
case mt: MethodType if mt.isImplicitMethod =>
resultTypeApprox(mt)
stripImplicit(resultTypeApprox(mt))
case pt: PolyType =>
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType, weight))
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
case _ =>
tp
}
Expand All @@ -1408,8 +1408,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>

val fullType1 = widenImplied(alt1.widen, alt1)
val fullType2 = widenImplied(alt2.widen, alt2)
val strippedType1 = stripImplicit(fullType1, -1)
val strippedType2 = stripImplicit(fullType2, +1)
val strippedType1 = stripImplicit(fullType1)
val strippedType2 = stripImplicit(fullType2)

val result = compareWithTypes(strippedType1, strippedType2)
if (result != 0) result
Expand Down
8 changes: 8 additions & 0 deletions tests/run/implied-specifity-2.scala
Expand Up @@ -29,8 +29,16 @@ object Baz {
implied baz given High for Foo[Bar[Baz]](5)
}

class Arg
implied for Arg

class Bam(val str: String)
implied lo given Low for Bam("lo")
implied hi given High given Arg for Bam("hi")

object Test extends App {
assert(Foo[Int] == 0)
assert(Foo[Bar[Int]] == 3)
assert(Foo[Bar[Baz]] == 5)
assert(the[Bam].str == "hi")
}

0 comments on commit cd9a29f

Please sign in to comment.