From a4599a56cbc99eb673d993ac516f1a7e6f86b41f Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 12 Sep 2019 16:40:47 +0200 Subject: [PATCH 01/11] Fix #6190: eta-expand companion object if functions are expected --- .../src/dotty/tools/dotc/ast/Desugar.scala | 24 +------------------ .../src/dotty/tools/dotc/typer/Typer.scala | 22 ++++++++++------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index c08f215ff6ff..e84e0396b5da 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -676,28 +676,6 @@ object desugar { mods.is(Private) || (!mods.is(Protected) && mods.hasPrivateWithin) } - /** Does one of the parameter's types (in the first param clause) - * mention a preceding parameter? - */ - def isParamDependent = constrVparamss match - case vparams :: _ => - val paramNames = vparams.map(_.name).toSet - vparams.exists(_.tpt.existsSubTree { - case Ident(name: TermName) => paramNames.contains(name) - case _ => false - }) - case _ => false - - val companionParent = - if constrTparams.nonEmpty - || constrVparamss.length > 1 - || mods.is(Abstract) - || restrictedAccess - || isParamDependent - || isEnumCase - then anyRef - else - constrVparamss.foldRight(classTypeRef)((vparams, restpe) => Function(vparams map (_.tpt), restpe)) val applyMeths = if (mods.is(Abstract)) Nil else { @@ -727,7 +705,7 @@ object desugar { val toStringMeth = DefDef(nme.toString_, Nil, Nil, TypeTree(), Literal(Constant(className.toString))).withMods(Modifiers(Override | Synthetic)) - companionDefs(companionParent, applyMeths ::: unapplyMeth :: toStringMeth :: companionMembers) + companionDefs(anyRef, applyMeths ::: unapplyMeth :: toStringMeth :: companionMembers) } else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum) companionDefs(anyRef, companionMembers) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 36825dbb6ec1..349686dc2a9d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3222,9 +3222,6 @@ class Typer extends Namer * Examples for these cases are found in run/implicitFuns.scala and neg/i2006.scala. */ def adaptNoArgsUnappliedMethod(wtp: MethodType, functionExpected: Boolean, arity: Int): Tree = { - def isExpandableApply = - defn.isContextFunctionClass(tree.symbol.maybeOwner) && functionExpected - /** Is reference to this symbol `f` automatically expanded to `f()`? */ def isAutoApplied(sym: Symbol): Boolean = sym.isConstructor @@ -3241,7 +3238,7 @@ class Typer extends Namer !tree.symbol.isConstructor && !tree.symbol.isAllOf(InlineMethod) && !ctx.mode.is(Mode.Pattern) && - !(isSyntheticApply(tree) && !isExpandableApply)) { + !(isSyntheticApply(tree) && !functionExpected)) { if (!defn.isFunctionType(pt)) pt match { case SAMType(_) if !pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot) => @@ -3266,9 +3263,18 @@ class Typer extends Namer defn.isContextFunctionClass(underlying.classSymbol) } - def adaptNoArgsOther(wtp: Type): Tree = { - if (isContextFunctionRef(wtp) && - !untpd.isContextualClosure(tree) && + def adaptNoArgsOther(wtp: Type, functionExpected: Boolean): Tree = { + val implicitFun = isContextFunctionRef(wtp) && !untpd.isContextualClosure(tree) + def caseCompanion = + functionExpected && + tree.symbol.is(Module) && + tree.symbol.companionClass.is(Case) && + !tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && { + report.warning("The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + ".apply` explicitly.", tree.sourcePos) + true + } + + if ((implicitFun || caseCompanion) && !isApplyProto(pt) && pt != AssignProto && !ctx.mode.is(Mode.Pattern) && @@ -3390,7 +3396,7 @@ class Typer extends Namer } adaptNoArgsUnappliedMethod(wtp, funExpected, arity) case _ => - adaptNoArgsOther(wtp) + adaptNoArgsOther(wtp, functionExpected) } } From be3502c72e60d882662c3bd025c98fa32debecab Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 12 Sep 2019 17:03:06 +0200 Subject: [PATCH 02/11] Refactor isSyntheticApply: use the same logic for consistency --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 8 -------- compiler/src/dotty/tools/dotc/typer/Typer.scala | 16 ++++++++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 9ba7030b6292..6dde5cf33c74 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -586,14 +586,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => case _ => false } - /** Is tree a compiler-generated `.apply` node that refers to the - * apply of a function class? - */ - def isSyntheticApply(tree: Tree): Boolean = tree match { - case Select(qual, nme.apply) => tree.span.end == qual.span.end - case _ => false - } - /** Strips layers of `.asInstanceOf[T]` / `_.$asInstanceOf[T]()` from an expression */ def stripCast(tree: Tree)(using Context): Tree = { def isCast(sel: Tree) = sel.symbol.isTypeCast diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 349686dc2a9d..80c3710795a7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -84,6 +84,14 @@ object Typer { */ private[typer] val HiddenSearchFailure = new Property.Key[List[SearchFailure]] + /** Is tree a compiler-generated `.apply` node that refers to the + * apply of a function class? + */ + private[typer] def isSyntheticApply(tree: tpd.Tree): Boolean = tree match { + case tree: tpd.Select => tree.hasAttachment(InsertedApply) + case _ => false + } + /** Add `fail` to the list of search failures attached to `tree` */ def rememberSearchFailure(tree: tpd.Tree, fail: SearchFailure) = tree.putAttachment(HiddenSearchFailure, @@ -2843,11 +2851,6 @@ class Typer extends Namer case _ => false } - def isSyntheticApply(tree: Tree): Boolean = tree match { - case tree: Select => tree.hasAttachment(InsertedApply) - case _ => false - } - def tryApply(using Context) = { val pt1 = pt.withContext(ctx) val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt1) @@ -3281,7 +3284,8 @@ class Typer extends Namer !ctx.isAfterTyper && !ctx.isInlineContext) { typr.println(i"insert apply on implicit $tree") - typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked) + val sel = untpd.Select(untpd.TypedSplice(tree), nme.apply).withAttachment(InsertedApply, ()) + try typed(sel, pt, locked) finally sel.removeAttachment(InsertedApply) } else if (ctx.mode is Mode.Pattern) { checkEqualityEvidence(tree, pt) From 8a0b3a9e2a6227cba22e0daecf859773af8c5ff1 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 12 Sep 2019 17:07:20 +0200 Subject: [PATCH 03/11] Fix tests --- .../src/dotty/tools/dottydoc/core/DocASTPhase.scala | 10 +++++----- tests/neg/enums.scala | 2 +- tests/{pos => neg}/t3137.scala | 2 +- tests/run-macros/tasty-extractors-2.check | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename tests/{pos => neg}/t3137.scala (80%) diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala index 33a297f73ef3..d9a1fde9781f 100644 --- a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -114,11 +114,11 @@ class DocASTPhase extends Phase { case c @ TypeDef(n, rhs) if c.symbol.isClass => //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well val parameters = (c.symbol, annotations(c.symbol), n.show, collectMembers(rhs), flags(c), path(c.symbol), typeParams(c.symbol), constructors(c.symbol), superTypes(c), None, Nil, None) - if (c.symbol.is(Flags.CaseClass)) { - CaseClassImpl.tupled(parameters) :: Nil - } else { - ClassImpl.tupled(parameters) :: Nil - } + val constr = + if (c.symbol.is(Flags.CaseClass)) CaseClassImpl.apply + else ClassImpl.apply + + constr.tupled(parameters) :: Nil /** def */ case d: DefDef => diff --git a/tests/neg/enums.scala b/tests/neg/enums.scala index a41c81bce3df..6335def433c1 100644 --- a/tests/neg/enums.scala +++ b/tests/neg/enums.scala @@ -22,7 +22,7 @@ enum E4 { case C4(x: Int) } object E4 { - val x1: Int => E4 = C4 // error: found: C4, required: Int => E4 + val x1: Int => E4 = C4 // ok val x2: Int => E4 = C4(_) // ok } diff --git a/tests/pos/t3137.scala b/tests/neg/t3137.scala similarity index 80% rename from tests/pos/t3137.scala rename to tests/neg/t3137.scala index cb7317af013d..6247617a2744 100644 --- a/tests/pos/t3137.scala +++ b/tests/neg/t3137.scala @@ -13,5 +13,5 @@ trait AA { } class BB extends AA { - case class C(v: Int) + case class C(v: Int) // error } diff --git a/tests/run-macros/tasty-extractors-2.check b/tests/run-macros/tasty-extractors-2.check index 0d9857e88e3f..f05c03ca384c 100644 --- a/tests/run-macros/tasty-extractors-2.check +++ b/tests/run-macros/tasty-extractors-2.check @@ -49,8 +49,8 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), Applied(Inferred(), List(Inferred()))), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Singleton(Literal(Constant.Boolean(true))), Some(Literal(Constant.Boolean(true)))), DefDef("toString", Nil, Nil, Inferred(), Some(Literal(Constant.String("Foo"))))))), Literal(Constant.Unit()))) -TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant(true))))))), Literal(Constant(())))) +Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(ClassDef("Foo1", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") From 901c5064e022fa0e287bdbd968ba6f480bfe3ccd Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 12 Sep 2019 22:00:11 +0200 Subject: [PATCH 04/11] Fix community projects --- community-build/community-projects/ScalaPB | 2 +- community-build/community-projects/fastparse | 2 +- community-build/community-projects/scalacheck | 2 +- community-build/community-projects/sourcecode | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/community-build/community-projects/ScalaPB b/community-build/community-projects/ScalaPB index 32513251893d..95515e8d052a 160000 --- a/community-build/community-projects/ScalaPB +++ b/community-build/community-projects/ScalaPB @@ -1 +1 @@ -Subproject commit 32513251893d583e0502b39d08613903e9f0f9eb +Subproject commit 95515e8d052a3b36f6fad168838e874420360de4 diff --git a/community-build/community-projects/fastparse b/community-build/community-projects/fastparse index e6e15f43003c..9b02d7050013 160000 --- a/community-build/community-projects/fastparse +++ b/community-build/community-projects/fastparse @@ -1 +1 @@ -Subproject commit e6e15f43003cbefc93bcd1209c37d8a4ed4d2f64 +Subproject commit 9b02d7050013fd7158f37f60116f3907d4a578e2 diff --git a/community-build/community-projects/scalacheck b/community-build/community-projects/scalacheck index a847e3f81fdb..428a370976cc 160000 --- a/community-build/community-projects/scalacheck +++ b/community-build/community-projects/scalacheck @@ -1 +1 @@ -Subproject commit a847e3f81fdb9fae520ffba25a4804b4b7205ddd +Subproject commit 428a370976ccad65f2d97406032c6d8fd3fe94c8 diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index 88b80f483f0c..25f3ef4bf9d9 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit 88b80f483f0c817addc097c90327cb423c254be1 +Subproject commit 25f3ef4bf9d9fc4d582640211ddb1e9c4493f889 From bc500a03df5508140be22fa92ec982d5a9b5d1b4 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sat, 14 Sep 2019 20:53:27 +0200 Subject: [PATCH 05/11] Address review: warning on insertion --- tests/neg-custom-args/fatal-warnings/i6190a.check | 0 tests/neg-custom-args/fatal-warnings/i6190b.check | 4 ++++ tests/neg-custom-args/fatal-warnings/i6190b.scala | 3 +++ tests/neg/i6190.scala | 6 ++++++ tests/pos-special/fatal-warnings/i6190a.scala | 6 ++++++ tests/pos-special/fatal-warnings/i6190c.scala | 3 +++ 6 files changed, 22 insertions(+) create mode 100644 tests/neg-custom-args/fatal-warnings/i6190a.check create mode 100644 tests/neg-custom-args/fatal-warnings/i6190b.check create mode 100644 tests/neg-custom-args/fatal-warnings/i6190b.scala create mode 100644 tests/neg/i6190.scala create mode 100644 tests/pos-special/fatal-warnings/i6190a.scala create mode 100644 tests/pos-special/fatal-warnings/i6190c.scala diff --git a/tests/neg-custom-args/fatal-warnings/i6190a.check b/tests/neg-custom-args/fatal-warnings/i6190a.check new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/neg-custom-args/fatal-warnings/i6190b.check b/tests/neg-custom-args/fatal-warnings/i6190b.check new file mode 100644 index 000000000000..8fc4e09896a9 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i6190b.check @@ -0,0 +1,4 @@ +-- Error: tests/neg-custom-args/fatal-warnings/i6190b.scala:3:29 ------------------------------------------------------- +3 |def foo = List("1", "2").map(Rule) // error + | ^^^^ + | The method `apply` is inserted. The auto insertion will be deprecated, please write `Rule.apply` explicitly. diff --git a/tests/neg-custom-args/fatal-warnings/i6190b.scala b/tests/neg-custom-args/fatal-warnings/i6190b.scala new file mode 100644 index 000000000000..470757791078 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i6190b.scala @@ -0,0 +1,3 @@ +case class Rule(name: String) + +def foo = List("1", "2").map(Rule) // error diff --git a/tests/neg/i6190.scala b/tests/neg/i6190.scala new file mode 100644 index 000000000000..65156f689104 --- /dev/null +++ b/tests/neg/i6190.scala @@ -0,0 +1,6 @@ +class Rule(name: String) +object Rule { + def apply(name: String): Rule = new Rule(name) +} + +def foo = List("1", "2").map(Rule) // error diff --git a/tests/pos-special/fatal-warnings/i6190a.scala b/tests/pos-special/fatal-warnings/i6190a.scala new file mode 100644 index 000000000000..e57238edf824 --- /dev/null +++ b/tests/pos-special/fatal-warnings/i6190a.scala @@ -0,0 +1,6 @@ +case class Rule(name: String) +object Rule extends (String => Rule) { + def apply(name: String): Rule = new Rule(name) +} + +def foo = List("1", "2").map(Rule) diff --git a/tests/pos-special/fatal-warnings/i6190c.scala b/tests/pos-special/fatal-warnings/i6190c.scala new file mode 100644 index 000000000000..b7ab530dddd9 --- /dev/null +++ b/tests/pos-special/fatal-warnings/i6190c.scala @@ -0,0 +1,3 @@ +case class Rule(name: String) + +def foo = List("1", "2").map(Rule.apply) From 7884d279e104033a7e24afb8a86d78d035c89bd1 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sun, 15 Sep 2019 15:17:32 +0200 Subject: [PATCH 06/11] Suppress apply insertion warnings in bootstrap --- .../src/dotty/tools/dotc/classpath/DirectoryClassPath.scala | 4 ++-- .../tools/dotc/classpath/VirtualDirectoryClassPath.scala | 2 +- doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala index 46f2fd1c7d62..8bf8d9f12079 100644 --- a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala @@ -195,7 +195,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No } case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[ClassFileEntryImpl] with NoSourcePaths { - override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl + override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl.apply def findClassFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) @@ -220,7 +220,7 @@ case class DirectorySourcePath(dir: JFile) extends JFileDirectoryLookup[SourceFi protected def createFileEntry(file: AbstractFile): SourceFileEntryImpl = SourceFileEntryImpl(file) protected def isMatchingFile(f: JFile): Boolean = endsScalaOrJava(f.getName) - override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className) map SourceFileEntryImpl + override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className) map SourceFileEntryImpl.apply private def findSourceFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) diff --git a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala index bea07504212b..335755406662 100644 --- a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala @@ -38,7 +38,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi def asURLs: Seq[URL] = Seq(new URL(dir.name)) def asClassPathStrings: Seq[String] = Seq(dir.path) - override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl + override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl.apply def findClassFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) + ".class" diff --git a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala index d478557df27f..ea2faac5fdc2 100644 --- a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala +++ b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala @@ -81,7 +81,7 @@ trait MemberLookup { ): EntityLink = { val link = lookup(Some(entity), packages, query) - .map(LinkToEntity) + .map(LinkToEntity.apply) .getOrElse(Tooltip(query)) EntityLink(title, link) From c5101cefd2c24c90146c64daeb0bb6da29d034dc Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 7 Dec 2020 13:40:42 +0100 Subject: [PATCH 07/11] Refactor code --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 80c3710795a7..cf4e200233f9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3272,7 +3272,7 @@ class Typer extends Namer functionExpected && tree.symbol.is(Module) && tree.symbol.companionClass.is(Case) && - !tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && { + !tree.tpe.baseClasses.exists(defn.isFunctionClass) && { report.warning("The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + ".apply` explicitly.", tree.sourcePos) true } From 631084cd2f7881ab7e6e19ca0727729f3ff98ebf Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 7 Dec 2020 13:42:41 +0100 Subject: [PATCH 08/11] Fix bootstrap: manual eta-expand to avoid warnings --- compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala | 6 +++--- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala b/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala index 7e7837bd3ac0..943d7c7bab6f 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala @@ -330,12 +330,12 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) { if (isProp) genExportProperty(alts, jsName, static) else - genExportMethod(alts.map(Exported), jsName, static) + genExportMethod(alts.map(Exported.apply), jsName, static) } } def genJSConstructorDispatch(alts: List[Symbol]): (Option[List[js.ParamDef]], js.JSMethodDef) = { - val exporteds = alts.map(Exported) + val exporteds = alts.map(Exported.apply) val isConstructorOfNestedJSClass = exporteds.head.isConstructorOfNestedJSClass assert(exporteds.tail.forall(_.isConstructorOfNestedJSClass == isConstructorOfNestedJSClass), @@ -391,7 +391,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) { } else { val formalArgsRegistry = new FormalArgsRegistry(1, false) val List(arg) = formalArgsRegistry.genFormalArgs() - val body = genExportSameArgc(jsName, formalArgsRegistry, setters.map(Exported), static, None) + val body = genExportSameArgc(jsName, formalArgsRegistry, setters.map(Exported.apply), static, None) Some((arg, body)) } } diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 0ccc1743ced7..58db604388cb 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -77,8 +77,8 @@ object Parsers { if source.isSelfContained then new ScriptParser(source) else new Parser(source) - private val InCase: Region => Region = Scanners.InCase - private val InCond: Region => Region = Scanners.InBraces + private val InCase: Region => Region = Scanners.InCase.apply + private val InCond: Region => Region = Scanners.InBraces.apply abstract class ParserCommon(val source: SourceFile)(using Context) { diff --git a/scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala b/scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala index 2282c19dfede..7f72e8b3778f 100644 --- a/scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala @@ -80,10 +80,10 @@ trait ScaladocSupport { self: TastyParser => addOpt(parsed.version)(dkkd.Version(_)) addOpt(parsed.since)(dkkd.Since(_)) addOpt(parsed.deprecated)(dkkd.Deprecated(_)) - addSeq(parsed.todo)(ScalaTagWrapper.Todo) - addSeq(parsed.see)(ScalaTagWrapper.See) - addSeq(parsed.note)(ScalaTagWrapper.Note) - addSeq(parsed.example)(ScalaTagWrapper.Example) + addSeq(parsed.todo)(ScalaTagWrapper.Todo.apply) + addSeq(parsed.see)(ScalaTagWrapper.See.apply) + addSeq(parsed.note)(ScalaTagWrapper.Note.apply) + addSeq(parsed.example)(ScalaTagWrapper.Example.apply) addOpt(parsed.constructor)(dkkd.Constructor(_)) addSeq(parsed.valueParams){ case (name, tag) => From 4cbc8345171e4d8d9f2c15bfbb8c3b0f97c85032 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 7 Dec 2020 14:14:02 +0100 Subject: [PATCH 09/11] Update check file --- tests/run-macros/tasty-extractors-2.check | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-macros/tasty-extractors-2.check b/tests/run-macros/tasty-extractors-2.check index f05c03ca384c..a4301fba7cb8 100644 --- a/tests/run-macros/tasty-extractors-2.check +++ b/tests/run-macros/tasty-extractors-2.check @@ -49,8 +49,8 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant(true))))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Singleton(Literal(Constant.Boolean(true))), Some(Literal(Constant.Boolean(true)))), DefDef("toString", Nil, Nil, Inferred(), Some(Literal(Constant.String("Foo"))))))), Literal(Constant.Unit()))) +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(ClassDef("Foo1", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") From 4ad153ac517aa244d6f571aec9c1f01bf355f132 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 7 Dec 2020 15:20:48 +0100 Subject: [PATCH 10/11] Fix endpoints4s --- community-build/community-projects/endpoints4s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/endpoints4s b/community-build/community-projects/endpoints4s index 43c9d9bba39a..66945205088f 160000 --- a/community-build/community-projects/endpoints4s +++ b/community-build/community-projects/endpoints4s @@ -1 +1 @@ -Subproject commit 43c9d9bba39aa316c0b9132595ff4e260c05ae0b +Subproject commit 66945205088fe63f21844ddf4919b9c622c72eb9 From 63eb4bfc178267965c346006fbd4e4155e728c19 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 8 Dec 2020 06:31:40 +0100 Subject: [PATCH 11/11] Enable warnings in log for collecting statistics --- community-build/src/scala/dotty/communitybuild/projects.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/src/scala/dotty/communitybuild/projects.scala b/community-build/src/scala/dotty/communitybuild/projects.scala index 2f55c6f4abad..2de4686ec218 100644 --- a/community-build/src/scala/dotty/communitybuild/projects.scala +++ b/community-build/src/scala/dotty/communitybuild/projects.scala @@ -150,7 +150,7 @@ final case class SbtCommunityProject( ) private val baseCommand = - "clean; set logLevel in Global := Level.Error; set updateOptions in Global ~= (_.withLatestSnapshots(false)); " + "clean; set updateOptions in Global ~= (_.withLatestSnapshots(false)); " ++ s"""set dependencyOverrides in ThisBuild ++= ${dependencyOverrides.mkString("Seq(", ", ", ")")}; """ ++ s"++$compilerVersion!; "