Skip to content

Commit f18d774

Browse files
authored
Don't search implicit arguments in singleton type prefix (#16490)
In a singleton type `f.type`, if `f` is a context function value, don't complete with implicit arguments. Fixes #16488
2 parents de26e9a + ebb2b22 commit f18d774

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ object ProtoTypes {
295295
*/
296296
@sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
297297

298+
@sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
299+
298300
/** A prototype for selections in pattern constructors */
299301
class UnapplySelectionProto(name: Name) extends SelectionProto(name, WildcardType, NoViewsAllowed, true)
300302

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19621962
completeTypeTree(InferredTypeTree(), pt, tree)
19631963

19641964
def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(using Context): SingletonTypeTree = {
1965-
val ref1 = typedExpr(tree.ref)
1965+
val ref1 = typedExpr(tree.ref, SingletonTypeProto)
19661966
checkStable(ref1.tpe, tree.srcPos, "singleton type")
19671967
assignType(cpy.SingletonTypeTree(tree)(ref1), ref1)
19681968
}
@@ -3773,20 +3773,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37733773
true
37743774
}
37753775

3776-
if ((implicitFun || caseCompanion) &&
3777-
!isApplyProto(pt) &&
3778-
pt != AssignProto &&
3779-
!ctx.mode.is(Mode.Pattern) &&
3780-
!ctx.isAfterTyper &&
3781-
!ctx.isInlineContext) {
3776+
if (implicitFun || caseCompanion)
3777+
&& !isApplyProto(pt)
3778+
&& pt != SingletonTypeProto
3779+
&& pt != AssignProto
3780+
&& !ctx.mode.is(Mode.Pattern)
3781+
&& !ctx.isAfterTyper
3782+
&& !ctx.isInlineContext
3783+
then
37823784
typr.println(i"insert apply on implicit $tree")
37833785
val sel = untpd.Select(untpd.TypedSplice(tree), nme.apply).withAttachment(InsertedApply, ())
37843786
try typed(sel, pt, locked) finally sel.removeAttachment(InsertedApply)
3785-
}
3786-
else if (ctx.mode is Mode.Pattern) {
3787+
else if ctx.mode is Mode.Pattern then
37873788
checkEqualityEvidence(tree, pt)
37883789
tree
3789-
}
37903790
else
37913791
val meth = methPart(tree).symbol
37923792
if meth.isAllOf(DeferredInline) && !Inlines.inInlineMethod then

tests/pos/i16488.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait Ctx
2+
val f: Ctx ?=> Int = ???
3+
type Tpe = f.type
4+

0 commit comments

Comments
 (0)