@@ -86,7 +86,25 @@ class Definitions {
86
86
newClassSymbol(ScalaPackageClass , name, EmptyFlags , completer).entered
87
87
}
88
88
89
- /** The trait FunctionN, for some N */
89
+ /** The trait FunctionN or ImplicitFunctionN, for some N
90
+ * @param name The name of the trait to be created
91
+ *
92
+ * FunctionN traits follow this template:
93
+ *
94
+ * trait FunctionN[T0,...T{N-1}, R] extends Object {
95
+ * def apply($x0: T0, ..., $x{N_1}: T{N-1}): R
96
+ * }
97
+ *
98
+ * That is, they follow the template given for Function2..Function22 in the
99
+ * standard library, but without `tupled` and `curried` methods and without
100
+ * a `toString`.
101
+ *
102
+ * ImplicitFunctionN traits follow this template:
103
+ *
104
+ * trait ImplicitFunctionN[T0,...,T{N-1}, R] extends Object with FunctionN[T0,...,T{N-1}, R] {
105
+ * def apply(implicit $x0: T0, ..., $x{N_1}: T{N-1}): R
106
+ * }
107
+ */
90
108
private def newFunctionNTrait (name : TypeName ) = {
91
109
val completer = new LazyType {
92
110
def complete (denot : SymDenotation )(implicit ctx : Context ): Unit = {
@@ -97,17 +115,17 @@ class Definitions {
97
115
for (i <- List .range(0 , arity)) yield
98
116
enterTypeParam(cls, name ++ " $T" ++ i.toString, Contravariant , decls)
99
117
val resParam = enterTypeParam(cls, name ++ " $R" , Covariant , decls)
100
- val (implicitFlag , parentTraits) =
118
+ val (methodType , parentTraits) =
101
119
if (name.startsWith(tpnme.ImplicitFunction )) {
102
120
val superTrait =
103
121
FunctionType (arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil )
104
- (Implicit , ctx.normalizeToClassRefs(superTrait :: Nil , cls, decls))
122
+ (ImplicitMethodType , ctx.normalizeToClassRefs(superTrait :: Nil , cls, decls))
105
123
}
106
- else (EmptyFlags , Nil )
124
+ else (MethodType , Nil )
107
125
val applyMeth =
108
126
decls.enter(
109
127
newMethod(cls, nme.apply,
110
- MethodType (argParams.map(_.typeRef), resParam.typeRef), Deferred | implicitFlag ))
128
+ methodType (argParams.map(_.typeRef), resParam.typeRef), Deferred ))
111
129
denot.info =
112
130
ClassInfo (ScalaPackageClass .thisType, cls, ObjectType :: parentTraits, decls)
113
131
}
@@ -696,6 +714,7 @@ class Definitions {
696
714
tp.derivesFrom(NothingClass ) || tp.derivesFrom(NullClass )
697
715
698
716
def isFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.Function )
717
+ def isImplicitFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.ImplicitFunction )
699
718
def isUnimplementedFunctionClass (cls : Symbol ) =
700
719
isFunctionClass(cls) && cls.name.functionArity > MaxImplementedFunctionArity
701
720
def isAbstractFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.AbstractFunction )
0 commit comments