Skip to content

Commit 7db2613

Browse files
committed
Add plain function tests to NameOps and Definitions
1 parent 1801a1f commit 7db2613

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,17 @@ class Definitions {
726726
def isBottomType(tp: Type) =
727727
tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)
728728

729-
/** Is a function class.
729+
/** Is any function class that satisfies:
730730
* - FunctionN for N >= 0
731731
* - ImplicitFunctionN for N >= 0
732732
*/
733733
def isFunctionClass(cls: Symbol) = scalaClassName(cls).isFunction
734734

735+
/** Is a function class where
736+
* - FunctionN for N >= 0
737+
*/
738+
def isPlainFunctionClass(cls: Symbol) = scalaClassName(cls).isPlainFunction
739+
735740
/** Is an implicit function class.
736741
* - ImplicitFunctionN for N >= 0
737742
*/

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ object NameOps {
240240
def functionArity: Int =
241241
functionArityFor(tpnme.Function) max functionArityFor(tpnme.ImplicitFunction)
242242

243-
/** Is a function name
243+
/** Is any function name that satisfies
244244
* - FunctionN for N >= 0
245245
* - ImplicitFunctionN for N >= 0
246-
* - false otherwise
247246
*/
248247
def isFunction: Boolean = functionArity >= 0
249248

249+
/** Is a function name
250+
* - FunctionN for N >= 0
251+
*/
252+
def isPlainFunction: Boolean = functionArityFor(tpnme.Function) >= 0
253+
250254
/** Is a implicit function name
251255
* - ImplicitFunctionN for N >= 0
252256
* - false otherwise

compiler/src/dotty/tools/dotc/transform/SpecializeFunction1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
180180
// Extractors ----------------------------------------------------------------
181181
private object ShouldTransformDenot {
182182
def unapply(cref: ClassDenotation)(implicit ctx: Context): Option[Seq[SpecializationTarget]] =
183-
if (!cref.classParents.map(_.symbol).exists(defn.isFunctionClass)) None
183+
if (!cref.classParents.map(_.symbol).exists(defn.isPlainFunctionClass)) None
184184
else Some(getSpecTargets(cref.typeRef))
185185
}
186186

@@ -207,7 +207,7 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
207207
val functionParents =
208208
tpe.classSymbols.iterator
209209
.flatMap(_.baseClasses)
210-
.filter(defn.isFunctionClass)
210+
.filter(defn.isPlainFunctionClass)
211211

212212
val tpeCls = tpe.widenDealias
213213
functionParents.map { sym =>

0 commit comments

Comments
 (0)