Skip to content

Fix #1916: fix erasure of implicit xxl closures #1936

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 8, 2017
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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 =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/run/implicitFunctionXXL.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello 42
38 changes: 38 additions & 0 deletions tests/run/implicitFunctionXXL.scala
Original file line number Diff line number Diff line change
@@ -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)
}

}