@@ -1413,7 +1413,12 @@ class Typer extends Namer
14131413 }
14141414 }
14151415
1416- def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(implicit ctx : Context ) = track(" typedDefDef" ) {
1416+ def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(implicit ctx : Context ): Tree = track(" typedDefDef" ) {
1417+ if (! sym.info.exists) { // it's a discarded synthetic case class method, drop it
1418+ assert(sym.is(Synthetic ) && desugar.isRetractableCaseClassMethodName(sym.name))
1419+ sym.owner.info.decls.openForMutations.unlink(sym)
1420+ return EmptyTree
1421+ }
14171422 val DefDef (name, tparams, vparamss, tpt, _) = ddef
14181423 completeAnnotations(ddef, sym)
14191424 val tparams1 = tparams mapconserve (typed(_).asInstanceOf [TypeDef ])
@@ -1911,7 +1916,8 @@ class Typer extends Namer
19111916 enumContexts(mdef1.symbol) = ctx
19121917 case _ =>
19131918 }
1914- buf += mdef1
1919+ if (! mdef1.isEmpty) // clashing synthetic case methods are converted to empty trees
1920+ buf += mdef1
19151921 }
19161922 traverse(rest)
19171923 }
@@ -1986,7 +1992,6 @@ class Typer extends Namer
19861992 * (but do this at most once per tree).
19871993 *
19881994 * After that, two strategies are tried, and the first that is successful is picked.
1989- * If neither of the strategies are successful, continues with`fallBack`.
19901995 *
19911996 * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`.
19921997 * This strategy is not tried if the prototype represents already
@@ -1995,6 +2000,10 @@ class Typer extends Namer
19952000 * 2nd strategy: If tree is a select `qual.name`, try to insert an implicit conversion
19962001 * around the qualifier part `qual` so that the result conforms to the expected type
19972002 * with wildcard result type.
2003+ *
2004+ * If neither of the strategies are successful, continues with the `apply` result
2005+ * if an apply insertion was tried and `tree` has an `apply` method, or continues
2006+ * with `fallBack` otherwise. `fallBack` is supposed to always give an error.
19982007 */
19992008 def tryInsertApplyOrImplicit (tree : Tree , pt : ProtoType , locked : TypeVars )(fallBack : => Tree )(implicit ctx : Context ): Tree = {
20002009
@@ -2016,7 +2025,7 @@ class Typer extends Namer
20162025 else try adapt(simplify(sel, pt, locked), pt, locked) finally sel.removeAttachment(InsertedApply )
20172026 }
20182027
2019- def tryImplicit =
2028+ def tryImplicit ( fallBack : => Tree ) =
20202029 tryInsertImplicitOnQualifier(tree, pt, locked).getOrElse(fallBack)
20212030
20222031 pt match {
@@ -2027,8 +2036,17 @@ class Typer extends Namer
20272036 pt.markAsDropped()
20282037 tree
20292038 case _ =>
2030- if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit
2031- else tryEither(tryApply(_))((_, _) => tryImplicit)
2039+ if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack)
2040+ else tryEither(tryApply(_)) { (app, appState) =>
2041+ tryImplicit {
2042+ if (tree.tpe.member(nme.apply).exists) {
2043+ // issue the error about the apply, since it is likely more informative than the fallback
2044+ appState.commit()
2045+ app
2046+ }
2047+ else fallBack
2048+ }
2049+ }
20322050 }
20332051 }
20342052
0 commit comments