From 50e40fffa866e5b41c5df93b3635165ab20e04b1 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 3 Feb 2017 10:57:54 +0100 Subject: Fix #1916: fix erasure of implicit xxl closures This commit extends the fix done in #1920 to implicit closures. --- .../src/dotty/tools/dotc/core/Definitions.scala | 4 +-- .../src/dotty/tools/dotc/core/TypeErasure.scala | 4 +-- .../src/dotty/tools/dotc/transform/Erasure.scala | 4 +-- tests/run/implicitFunctionXXL.check | 1 + tests/run/implicitFunctionXXL.scala | 38 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tests/run/implicitFunctionXXL.check create mode 100644 tests/run/implicitFunctionXXL.scala diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 7fe6505ff..866f6e7fa 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -733,8 +733,8 @@ class Definitions { def isFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.Function) def isImplicitFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.ImplicitFunction) - def isUnimplementedFunctionClass(cls: Symbol) = - isFunctionClass(cls) && cls.name.functionArity > MaxImplementedFunctionArity + /** Is a class that will be erased to FunctionXXL */ + def isXXLFunctionClass(cls: Symbol) = cls.name.functionArity > MaxImplementedFunctionArity def isAbstractFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.AbstractFunction) def isTupleClass(cls: Symbol) = isVarArityClass(cls, tpnme.Tuple) def isProductClass(cls: Symbol) = isVarArityClass(cls, tpnme.Product) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 91e37d440..2a341390b 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.isImplicitFunctionClass(sym) + !defn.isXXLFunctionClass(sym) && !defn.isImplicitFunctionClass(sym) case _: TermRef => true case JavaArrayType(elem) => @@ -358,7 +358,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean if (!sym.isClass) this(tp.info) else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp) else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type. - else if (defn.isUnimplementedFunctionClass(sym)) defn.FunctionXXLType + else if (defn.isXXLFunctionClass(sym)) defn.FunctionXXLType else if (defn.isImplicitFunctionClass(sym)) apply(defn.FunctionType(sym.name.functionArity)) else eraseNormalClassRef(tp) case tp: RefinedType => diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 00abddd91..bba97c4c2 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -349,7 +349,7 @@ object Erasure extends TypeTestsCasts{ if ((owner eq defn.AnyClass) || (owner eq defn.AnyValClass)) { assert(sym.isConstructor, s"${sym.showLocated}") defn.ObjectClass - } else if (defn.isUnimplementedFunctionClass(owner)) + } else if (defn.isXXLFunctionClass(owner)) defn.FunctionXXLClass else if (defn.isImplicitFunctionClass(owner)) recur(defn.FunctionClass(owner.name.functionArity)) @@ -542,7 +542,7 @@ object Erasure extends TypeTestsCasts{ * to deal with boxing and unboxing of value classes ourselves. */ override def typedClosure(tree: untpd.Closure, pt: Type)(implicit ctx: Context) = { - val xxl = defn.isUnimplementedFunctionClass(tree.typeOpt.typeSymbol) + val xxl = defn.isXXLFunctionClass(tree.typeOpt.typeSymbol) var implClosure @ Closure(_, meth, _) = super.typedClosure(tree, pt) if (xxl) implClosure = cpy.Closure(implClosure)(tpt = TypeTree(defn.FunctionXXLType)) implClosure.tpe match { diff --git a/tests/run/implicitFunctionXXL.check b/tests/run/implicitFunctionXXL.check new file mode 100644 index 000000000..87ff213a5 --- /dev/null +++ b/tests/run/implicitFunctionXXL.check @@ -0,0 +1 @@ +Hello 42 diff --git a/tests/run/implicitFunctionXXL.scala b/tests/run/implicitFunctionXXL.scala new file mode 100644 index 000000000..9d1d4ff37 --- /dev/null +++ b/tests/run/implicitFunctionXXL.scala @@ -0,0 +1,38 @@ +object Test { + + def main(args: Array[String]): Unit = { + + implicit val intWorld: Int = 42 + implicit val strWorld: String = "Hello " + + val i1 = (implicit (x1: Int, + x2: String, + x3: Int, + x4: Int, + x5: Int, + x6: Int, + x7: Int, + x8: Int, + x9: Int, + x10: Int, + x11: Int, + x12: Int, + x13: Int, + x14: Int, + x15: Int, + x16: Int, + x17: Int, + x18: Int, + x19: Int, + x20: Int, + x21: Int, + x22: Int, + x23: Int, + x24: Int, + x25: Int, + x26: Int) => x2 + x1) + + println(i1) + } + +} -- cgit v1.2.3