Skip to content

Commit ccd98c9

Browse files
committed
Fix #5966: Narrow criterion for when we have an inserted apply
`insertApplyOrImplicit` checks whether we already have an inserted apply in order to prevent an infinite insertion sequence. This criterion should be restricted to just look at Select nodes. Once an inserted `apply` is in fact applied it should not count anymore.
1 parent 0a5349d commit ccd98c9

File tree

6 files changed

+6
-8
lines changed

6 files changed

+6
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ object Trees {
432432
extends GenericApply[T] {
433433
type ThisTree[-T >: Untyped] = Apply[T]
434434

435-
def isContextual = getAttachment(untpd.WithApply).nonEmpty
435+
def isContextual = getAttachment(untpd.ApplyGiven).nonEmpty
436436
}
437437

438438
/** fun[args] */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
274274
*/
275275
val OriginalSymbol: Property.Key[Symbol] = new Property.Key
276276

277-
/** Property key for contextual Apply trees of the form `fn with arg` */
278-
val WithApply: Property.StickyKey[Unit] = new Property.StickyKey
277+
/** Property key for contextual Apply trees of the form `fn given arg` */
278+
val ApplyGiven: Property.StickyKey[Unit] = new Property.StickyKey
279279

280280
// ------ Creation methods for untyped only -----------------
281281

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ object Parsers {
548548
val args = if (in.token == LPAREN) parArgumentExprs() else operand() :: Nil
549549
Apply(top, args)
550550
}
551-
app.pushAttachment(WithApply, ())
551+
app.pushAttachment(ApplyGiven, ())
552552
recur(app)
553553
}
554554
else reduceStack(base, top, minPrec, leftAssoc = true, in.name, isType)

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
232232
case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp)
233233
case _ => toTextGlobal(args, ", ")
234234
}
235-
return "FunProto(" ~ argsText ~ "):" ~ toText(resultType)
235+
return "FunProto(" ~ (Str("given ") provided tp.isContextual) ~ argsText ~ "):" ~ toText(resultType)
236236
case IgnoredProto(ignored) =>
237237
return "?" ~ (("(ignored: " ~ toText(ignored) ~ ")") provided ctx.settings.verbose.value)
238238
case tp @ PolyProto(targs, resType) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ object EtaExpansion extends LiftImpure {
218218
if (mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam)
219219
ids = ids.init :+ repeated(ids.last)
220220
var body: Tree = Apply(lifted, ids)
221-
if (mt.isContextual) body.pushAttachment(WithApply, ())
221+
if (mt.isContextual) body.pushAttachment(ApplyGiven, ())
222222
if (!isLastApplication) body = PostfixOp(body, Ident(nme.WILDCARD))
223223
val fn =
224224
if (mt.isContextual) new untpd.FunctionWithMods(params, body, Modifiers(Implicit | Given))

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,15 +2200,13 @@ class Typer extends Namer
22002200
* with `fallBack` otherwise. `fallBack` is supposed to always give an error.
22012201
*/
22022202
def tryInsertApplyOrImplicit(tree: Tree, pt: ProtoType, locked: TypeVars)(fallBack: => Tree)(implicit ctx: Context): Tree = {
2203-
22042203
def isMethod(tree: Tree) = tree.tpe match {
22052204
case ref: TermRef => ref.denot.alternatives.forall(_.info.widen.isInstanceOf[MethodicType])
22062205
case _ => false
22072206
}
22082207

22092208
def isSyntheticApply(tree: Tree): Boolean = tree match {
22102209
case tree: Select => tree.getAttachment(InsertedApply).isDefined
2211-
case Apply(fn, _) => fn.getAttachment(InsertedApply).isDefined
22122210
case _ => false
22132211
}
22142212

0 commit comments

Comments
 (0)