Skip to content

Commit be3502c

Browse files
committed
Refactor isSyntheticApply: use the same logic for consistency
1 parent a4599a5 commit be3502c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

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

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

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

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ object Typer {
8484
*/
8585
private[typer] val HiddenSearchFailure = new Property.Key[List[SearchFailure]]
8686

87+
/** Is tree a compiler-generated `.apply` node that refers to the
88+
* apply of a function class?
89+
*/
90+
private[typer] def isSyntheticApply(tree: tpd.Tree): Boolean = tree match {
91+
case tree: tpd.Select => tree.hasAttachment(InsertedApply)
92+
case _ => false
93+
}
94+
8795
/** Add `fail` to the list of search failures attached to `tree` */
8896
def rememberSearchFailure(tree: tpd.Tree, fail: SearchFailure) =
8997
tree.putAttachment(HiddenSearchFailure,
@@ -2843,11 +2851,6 @@ class Typer extends Namer
28432851
case _ => false
28442852
}
28452853

2846-
def isSyntheticApply(tree: Tree): Boolean = tree match {
2847-
case tree: Select => tree.hasAttachment(InsertedApply)
2848-
case _ => false
2849-
}
2850-
28512854
def tryApply(using Context) = {
28522855
val pt1 = pt.withContext(ctx)
28532856
val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt1)
@@ -3281,7 +3284,8 @@ class Typer extends Namer
32813284
!ctx.isAfterTyper &&
32823285
!ctx.isInlineContext) {
32833286
typr.println(i"insert apply on implicit $tree")
3284-
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)
3287+
val sel = untpd.Select(untpd.TypedSplice(tree), nme.apply).withAttachment(InsertedApply, ())
3288+
try typed(sel, pt, locked) finally sel.removeAttachment(InsertedApply)
32853289
}
32863290
else if (ctx.mode is Mode.Pattern) {
32873291
checkEqualityEvidence(tree, pt)

0 commit comments

Comments
 (0)