diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 2 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/Erasure.scala | 28 | ||||
-rw-r--r-- | tests/pending/run/implicitFuns.scala | 32 | ||||
-rw-r--r-- | tests/pos/implicitFuns.scala | 36 |
4 files changed, 48 insertions, 50 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index bc736b229..6b682b028 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -44,7 +44,7 @@ object TypeErasure { val sym = tp.symbol sym.isClass && sym != defn.AnyClass && sym != defn.ArrayClass && - !defn.isUnimplementedFunctionClass(sym) + !defn.isUnimplementedFunctionClass(sym) && !defn.isImplicitFunctionClass(sym) case _: TermRef => true case JavaArrayType(elem) => diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 7595e5f2e..71ecb5c65 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -345,21 +345,23 @@ object Erasure extends TypeTestsCasts{ override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = { def mapOwner(sym: Symbol): Symbol = { - val owner = sym.owner - if ((owner eq defn.AnyClass) || (owner eq defn.AnyValClass)) { - assert(sym.isConstructor, s"${sym.showLocated}") - defn.ObjectClass - } - else if (defn.isUnimplementedFunctionClass(owner)) - defn.FunctionXXLClass - else - owner + def recur(owner: Symbol): Symbol = + if ((owner eq defn.AnyClass) || (owner eq defn.AnyValClass)) { + assert(sym.isConstructor, s"${sym.showLocated}") + defn.ObjectClass + } else if (defn.isUnimplementedFunctionClass(owner)) + defn.FunctionXXLClass + else if (defn.isImplicitFunctionClass(owner)) + recur(defn.FunctionClass(owner.name.functionArity)) + else + owner + recur(sym.owner) } - var sym = tree.symbol - val owner = mapOwner(sym) - if (owner ne sym.owner) sym = owner.info.decl(sym.name).symbol - assert(sym.exists, owner) + val origSym = tree.symbol + val owner = mapOwner(origSym) + val sym = if (owner eq origSym.owner) origSym else owner.info.decl(origSym.name).symbol + assert(sym.exists, origSym.showLocated) def select(qual: Tree, sym: Symbol): Tree = { val name = tree.typeOpt match { diff --git a/tests/pending/run/implicitFuns.scala b/tests/pending/run/implicitFuns.scala new file mode 100644 index 000000000..1b7ca694a --- /dev/null +++ b/tests/pending/run/implicitFuns.scala @@ -0,0 +1,32 @@ +object Test { + def main(args: Array[String]) = { + + implicit val world: String = "world!" + + val i1 = (implicit (s: String) => s.length > 2) + val i2 = {implicit (s: String) => s.length > 2} + + assert(i1) + assert(i2) + + val x: implicit String => Boolean = { implicit (s: String) => s.length > 2 } + + val xx: implicit (String, Int) => Int = implicit (x: String, y: Int) => x.length + y + + val y: String => Boolean = x + + val yy: (String, Int) => Any = xx + + val b = x("hello") + + val b1: Boolean = b + + val bi = x + + val bi1: Boolean = bi + + val c = xx("hh", 22) + + val c1: Int = c + } +} diff --git a/tests/pos/implicitFuns.scala b/tests/pos/implicitFuns.scala deleted file mode 100644 index edb2434c9..000000000 --- a/tests/pos/implicitFuns.scala +++ /dev/null @@ -1,36 +0,0 @@ -object Test { - - val x: ImplicitFunction1[String, Boolean] = ??? - - val y: String => Boolean = x - - val b = x("hello") - - val b1: Boolean = b - -} -object Test2 { - - val x: implicit String => Boolean = ??? - - val xx: implicit (String, Int) => Int = ??? - - val y: String => Boolean = x - - val yy: (String, Int) => Any = xx - - implicit val world: String = "world!" - - val b = x("hello") - - val b1: Boolean = b - - val bi = x - - val bi1: Boolean = bi - - val c = xx("hh", 22) - - val c1: Int = c - -} |