Skip to content

Commit 748b8f4

Browse files
committed
Infer if overloading resolution should trigger implicit search.
This doesn't require additional argument. Decision can be made solely from the phaseId.
1 parent f46c977 commit 748b8f4

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

src/dotty/tools/dotc/core/pickling/UnPickler.scala

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -815,42 +815,37 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
815815
* readAnnotation, readSymbolAnnotation, or readAnnotInfoArg
816816
*/
817817
protected def readAnnotationContents(end: Int)(implicit ctx: Context): Tree = {
818-
ctx.atPhase(ctx.typerPhase) { implicit ctx => // needed to enable implicit search
819-
// and fix circullar dependency between annotation.currect invoking
820-
// elimrepeated that reads the same annotation
821-
822-
val atp = readTypeRef()
823-
val args = {
824-
val t = new ListBuffer[Tree]
825-
826-
while (readIndex != end) {
827-
val argref = readNat()
828-
t += {
829-
if (isNameEntry(argref)) {
830-
val name = at(argref, readName)
831-
val arg = readClassfileAnnotArg(readNat())
832-
NamedArg(name.asTermName, arg)
833-
} else readAnnotArg(argref)
834-
}
818+
val atp = readTypeRef()
819+
val args = {
820+
val t = new ListBuffer[Tree]
821+
822+
while (readIndex != end) {
823+
val argref = readNat()
824+
t += {
825+
if (isNameEntry(argref)) {
826+
val name = at(argref, readName)
827+
val arg = readClassfileAnnotArg(readNat())
828+
NamedArg(name.asTermName, arg)
829+
} else readAnnotArg(argref)
835830
}
836-
t.toList
837831
}
838-
println(atp)
839-
val typer = ctx.typer
840-
val proto = new FunProtoTyped(args, atp, typer)
841-
val alts = atp.member(nme.CONSTRUCTOR).alternatives.map(_.termRef)
842-
843-
val constructors = ctx.typer.resolveOverloaded(alts, proto, Nil, false)
844-
assert(constructors.size == 1) // this is parsed from bytecode tree. there's nothing user can do about it
845-
846-
val constr = constructors.head
847-
val targs = atp.argTypes
848-
val fun = tpd.New(atp withoutArgs targs)
849-
.select(TermRef.withSig(atp.normalizedPrefix, constr.termSymbol.asTerm))
850-
.appliedToTypes(targs)
851-
val apply = untpd.Apply(fun, args)
852-
new typer.ApplyToTyped(apply, fun, constr, args, atp).result // needed to handle varargs
832+
t.toList
853833
}
834+
println(atp)
835+
val typer = ctx.typer
836+
val proto = new FunProtoTyped(args, atp, typer)
837+
val alts = atp.member(nme.CONSTRUCTOR).alternatives.map(_.termRef)
838+
839+
val constructors = ctx.typer.resolveOverloaded(alts, proto, Nil)
840+
assert(constructors.size == 1) // this is parsed from bytecode tree. there's nothing user can do about it
841+
842+
val constr = constructors.head
843+
val targs = atp.argTypes
844+
val fun = tpd.New(atp withoutArgs targs)
845+
.select(TermRef.withSig(atp.normalizedPrefix, constr.termSymbol.asTerm))
846+
.appliedToTypes(targs)
847+
val apply = untpd.Apply(fun, args)
848+
new typer.ApplyToTyped(apply, fun, constr, args, atp).result // needed to handle varargs
854849
}
855850

856851
/** Read an annotation and as a side effect store it into

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ trait Applications extends Compatibility { self: Typer =>
902902
* to form the method type.
903903
* todo: use techniques like for implicits to pick candidates quickly?
904904
*/
905-
def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type] = Nil, resolveImplicits: Boolean = true)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
905+
def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type] = Nil)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
906906

907907
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
908908

@@ -960,7 +960,7 @@ trait Applications extends Compatibility { self: Typer =>
960960

961961
def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] =
962962
alts filter ( alt =>
963-
if (resolveImplicits) isApplicable(alt, targs, args, resultType)
963+
if (!ctx.isAfterTyper) isApplicable(alt, targs, args, resultType)
964964
else isDirectlyApplicable(alt, targs, args, resultType)
965965
)
966966

0 commit comments

Comments
 (0)