Skip to content

Commit d61d7f9

Browse files
authored
Merge pull request #7207 from dotty-staging/fix-6190
Fix #6190: eta-expand companion object if functions are expected
2 parents eab8783 + 63eb4bf commit d61d7f9

File tree

25 files changed

+74
-72
lines changed

25 files changed

+74
-72
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ final case class SbtCommunityProject(
150150
)
151151

152152
private val baseCommand =
153-
"clean; set logLevel in Global := Level.Error; set updateOptions in Global ~= (_.withLatestSnapshots(false)); "
153+
"clean; set updateOptions in Global ~= (_.withLatestSnapshots(false)); "
154154
++ s"""set dependencyOverrides in ThisBuild ++= ${dependencyOverrides.mkString("Seq(", ", ", ")")}; """
155155
++ s"++$compilerVersion!; "
156156

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
330330
if (isProp)
331331
genExportProperty(alts, jsName, static)
332332
else
333-
genExportMethod(alts.map(Exported), jsName, static)
333+
genExportMethod(alts.map(Exported.apply), jsName, static)
334334
}
335335
}
336336

337337
def genJSConstructorDispatch(alts: List[Symbol]): (Option[List[js.ParamDef]], js.JSMethodDef) = {
338-
val exporteds = alts.map(Exported)
338+
val exporteds = alts.map(Exported.apply)
339339

340340
val isConstructorOfNestedJSClass = exporteds.head.isConstructorOfNestedJSClass
341341
assert(exporteds.tail.forall(_.isConstructorOfNestedJSClass == isConstructorOfNestedJSClass),
@@ -391,7 +391,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
391391
} else {
392392
val formalArgsRegistry = new FormalArgsRegistry(1, false)
393393
val List(arg) = formalArgsRegistry.genFormalArgs()
394-
val body = genExportSameArgc(jsName, formalArgsRegistry, setters.map(Exported), static, None)
394+
val body = genExportSameArgc(jsName, formalArgsRegistry, setters.map(Exported.apply), static, None)
395395
Some((arg, body))
396396
}
397397
}

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -676,28 +676,6 @@ object desugar {
676676
mods.is(Private) || (!mods.is(Protected) && mods.hasPrivateWithin)
677677
}
678678

679-
/** Does one of the parameter's types (in the first param clause)
680-
* mention a preceding parameter?
681-
*/
682-
def isParamDependent = constrVparamss match
683-
case vparams :: _ =>
684-
val paramNames = vparams.map(_.name).toSet
685-
vparams.exists(_.tpt.existsSubTree {
686-
case Ident(name: TermName) => paramNames.contains(name)
687-
case _ => false
688-
})
689-
case _ => false
690-
691-
val companionParent =
692-
if constrTparams.nonEmpty
693-
|| constrVparamss.length > 1
694-
|| mods.is(Abstract)
695-
|| restrictedAccess
696-
|| isParamDependent
697-
|| isEnumCase
698-
then anyRef
699-
else
700-
constrVparamss.foldRight(classTypeRef)((vparams, restpe) => Function(vparams map (_.tpt), restpe))
701679
val applyMeths =
702680
if (mods.is(Abstract)) Nil
703681
else {
@@ -727,7 +705,7 @@ object desugar {
727705
val toStringMeth =
728706
DefDef(nme.toString_, Nil, Nil, TypeTree(), Literal(Constant(className.toString))).withMods(Modifiers(Override | Synthetic))
729707

730-
companionDefs(companionParent, applyMeths ::: unapplyMeth :: toStringMeth :: companionMembers)
708+
companionDefs(anyRef, applyMeths ::: unapplyMeth :: toStringMeth :: companionMembers)
731709
}
732710
else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum)
733711
companionDefs(anyRef, companionMembers)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
585585
case _ => false
586586
}
587587

588-
/** Is tree a compiler-generated `.apply` node that refers to the
589-
* apply of a function class?
590-
*/
591-
def isSyntheticApply(tree: Tree): Boolean = tree match {
592-
case Select(qual, nme.apply) => tree.span.end == qual.span.end
593-
case _ => false
594-
}
595-
596588
/** Strips layers of `.asInstanceOf[T]` / `_.$asInstanceOf[T]()` from an expression */
597589
def stripCast(tree: Tree)(using Context): Tree = {
598590
def isCast(sel: Tree) = sel.symbol.isTypeCast

compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
195195
}
196196

197197
case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[ClassFileEntryImpl] with NoSourcePaths {
198-
override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl
198+
override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl.apply
199199

200200
def findClassFile(className: String): Option[AbstractFile] = {
201201
val relativePath = FileUtils.dirPath(className)
@@ -220,7 +220,7 @@ case class DirectorySourcePath(dir: JFile) extends JFileDirectoryLookup[SourceFi
220220
protected def createFileEntry(file: AbstractFile): SourceFileEntryImpl = SourceFileEntryImpl(file)
221221
protected def isMatchingFile(f: JFile): Boolean = endsScalaOrJava(f.getName)
222222

223-
override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className) map SourceFileEntryImpl
223+
override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className) map SourceFileEntryImpl.apply
224224

225225
private def findSourceFile(className: String): Option[AbstractFile] = {
226226
val relativePath = FileUtils.dirPath(className)

0 commit comments

Comments
 (0)