diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 6fb019ee057c..8ba842ad695f 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -295,6 +295,8 @@ object ProtoTypes { */ @sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true) + @sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true) + /** A prototype for selections in pattern constructors */ class UnapplySelectionProto(name: Name) extends SelectionProto(name, WildcardType, NoViewsAllowed, true) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 1f6516cdfb1c..9b56de5a25df 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1962,7 +1962,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer completeTypeTree(InferredTypeTree(), pt, tree) def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(using Context): SingletonTypeTree = { - val ref1 = typedExpr(tree.ref) + val ref1 = typedExpr(tree.ref, SingletonTypeProto) checkStable(ref1.tpe, tree.srcPos, "singleton type") assignType(cpy.SingletonTypeTree(tree)(ref1), ref1) } @@ -3773,20 +3773,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer true } - if ((implicitFun || caseCompanion) && - !isApplyProto(pt) && - pt != AssignProto && - !ctx.mode.is(Mode.Pattern) && - !ctx.isAfterTyper && - !ctx.isInlineContext) { + if (implicitFun || caseCompanion) + && !isApplyProto(pt) + && pt != SingletonTypeProto + && pt != AssignProto + && !ctx.mode.is(Mode.Pattern) + && !ctx.isAfterTyper + && !ctx.isInlineContext + then typr.println(i"insert apply on implicit $tree") 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) { + else if ctx.mode is Mode.Pattern then checkEqualityEvidence(tree, pt) tree - } else val meth = methPart(tree).symbol if meth.isAllOf(DeferredInline) && !Inlines.inInlineMethod then diff --git a/tests/pos/i16488.scala b/tests/pos/i16488.scala new file mode 100644 index 000000000000..f601c5aa8074 --- /dev/null +++ b/tests/pos/i16488.scala @@ -0,0 +1,4 @@ +trait Ctx +val f: Ctx ?=> Int = ??? +type Tpe = f.type +