Skip to content

Commit 37c4f1f

Browse files
committed
Tweaks and more comments
1 parent 73c155a commit 37c4f1f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ object ProtoTypes {
4545
}
4646
if (keepConstraint)
4747
tp.widenSingleton match {
48-
case poly: PolyType => normalizedCompatible(tp, pt, keepConstraint = false)
48+
case poly: PolyType =>
49+
// We can't keep the constraint in this case, since we have to add type parameters
50+
// to it, but there's no place to associate them with type variables.
51+
// So we'd get a "inconsistent: no typevars were added to committable constraint"
52+
// assertion failure in `constrained`. To do better, we'd have to change the
53+
// constraint handling architecture so that some type parameters are committable
54+
// and others are not. But that's a whole different ballgame.
55+
normalizedCompatible(tp, pt, keepConstraint = false)
4956
case _ => testCompat
5057
}
5158
else ctx.test(implicit ctx => testCompat)
@@ -196,8 +203,18 @@ object ProtoTypes {
196203
def selectionProto(name: Name, tp: Type, typer: Typer)(implicit ctx: Context): TermType =
197204
if (name.isConstructorName) WildcardType
198205
else tp match {
199-
case tp: UnapplyFunProto => new UnapplySelectionProto(name)
200-
case tp => SelectionProto(name, IgnoredProto(tp), typer, privateOK = true)
206+
case tp: UnapplyFunProto =>
207+
new UnapplySelectionProto(name)
208+
case tp =>
209+
val memberProto =
210+
if (ctx.mode.is(Mode.SynthesizeExtMethodReceiver)) tp
211+
else IgnoredProto(tp)
212+
// Disregard what's known about the member in the selection prototype.
213+
// This allows implicit conversions to be applied on the member
214+
// and avoids duplicated computations. Exception: when synthesizing
215+
// the receiver of an extension method, we do take the type of the first
216+
// argument into sccount.
217+
SelectionProto(name, memberProto, typer, privateOK = true)
201218
}
202219

203220
/** A prototype for expressions [] that are in some unspecified selection operation
@@ -246,6 +263,8 @@ object ProtoTypes {
246263
def isMatchedBy(tp: Type, keepConstraint: Boolean)(implicit ctx: Context): Boolean = {
247264
val args = unforcedTypedArgs
248265
def isPoly(tree: Tree) = tree.tpe.widenSingleton.isInstanceOf[PolyType]
266+
// See remark in normalizedCompatible for why we can't keep the constraint
267+
// if one of the arguments has a PolyType.
249268
typer.isApplicable(tp, Nil, args, resultType, keepConstraint && !args.exists(isPoly))
250269
}
251270

@@ -308,7 +327,7 @@ object ProtoTypes {
308327
if (state.typedArgs.size == args.length) state.typedArgs
309328
else {
310329
val args1 = args.mapconserve(cacheTypedArg(_, typer.typed(_), force))
311-
if (!args1.contains(WildcardType)) state.typedArgs = args1
330+
if (force || !args1.contains(WildcardType)) state.typedArgs = args1
312331
args1
313332
}
314333

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,13 +2397,6 @@ class Typer extends Namer
23972397
}
23982398
}
23992399

2400-
/** Reveal ignored parts of prototype when synthesizing the receiver
2401-
* of an extension method. This is necessary for pos/i5773.scala
2402-
*/
2403-
def revealProtoOfExtMethod(tp: Type)(implicit ctx: Context): Type =
2404-
if (ctx.mode.is(Mode.SynthesizeExtMethodReceiver)) tp.deepenProto
2405-
else tp
2406-
24072400
def adaptNoArgsImplicitMethod(wtp: MethodType): Tree = {
24082401
assert(wtp.isImplicitMethod)
24092402
val tvarsToInstantiate = tvarsInParams(tree, locked).distinct
@@ -2616,7 +2609,7 @@ class Typer extends Namer
26162609
}
26172610

26182611
def resultMatches(wtp: Type, pt: Type) =
2619-
constrainResult(tree.symbol, wtp, revealProtoOfExtMethod(followAlias(pt)))
2612+
constrainResult(tree.symbol, wtp, followAlias(pt))
26202613

26212614
def adaptNoArgs(wtp: Type): Tree = {
26222615
val ptNorm = underlyingApplied(pt)

0 commit comments

Comments
 (0)