Skip to content

Commit 83c3de7

Browse files
committed
Make the SAMType extractor return a type, not a denot
1 parent 0c5e39d commit 83c3de7

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,8 +3783,8 @@ object Types {
37833783
* and PolyType not allowed!)
37843784
* - can be instantiated without arguments or with just () as argument.
37853785
*
3786-
* The pattern `SAMType(denot)` matches a SAM type, where `denot` is the
3787-
* denotation of the single abstract method as a member of the type.
3786+
* The pattern `SAMType(sam)` matches a SAM type, where `sam` is the
3787+
* type of the single abstract method.
37883788
*/
37893789
object SAMType {
37903790
def zeroParamClass(tp: Type)(implicit ctx: Context): Type = tp match {
@@ -3817,14 +3817,16 @@ object Types {
38173817
case _ =>
38183818
false
38193819
}
3820-
def unapply(tp: Type)(implicit ctx: Context): Option[SingleDenotation] =
3820+
def unapply(tp: Type)(implicit ctx: Context): Option[MethodType] =
38213821
if (isInstantiatable(tp)) {
38223822
val absMems = tp.abstractTermMembers
38233823
// println(s"absMems: ${absMems map (_.show) mkString ", "}")
38243824
if (absMems.size == 1)
38253825
absMems.head.info match {
3826-
case mt: MethodType if !mt.isParamDependent => Some(absMems.head)
3827-
case _ => None
3826+
case mt: MethodType if !mt.isParamDependent =>
3827+
Some(mt)
3828+
case _ =>
3829+
None
38283830
}
38293831
else if (tp isRef defn.PartialFunctionClass)
38303832
// To maintain compatibility with 2.x, we treat PartialFunction specially,
@@ -3833,7 +3835,7 @@ object Types {
38333835
// def isDefinedAt(x: T) = true
38343836
// and overwrite that method whenever the function body is a sequence of
38353837
// case clauses.
3836-
absMems.find(_.symbol.name == nme.apply)
3838+
absMems.find(_.symbol.name == nme.apply).map(_.info.asInstanceOf[MethodType])
38373839
else None
38383840
}
38393841
else None

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,9 @@ object Erasure {
577577
val implType = meth.tpe.widen.asInstanceOf[MethodType]
578578

579579
val implParamTypes = implType.paramInfos
580-
val List(samParamTypes) = sam.info.paramInfoss
580+
val List(samParamTypes) = sam.paramInfoss
581581
val implResultType = implType.resultType
582-
val samResultType = sam.info.resultType
582+
val samResultType = sam.resultType
583583

584584
// The following code:
585585
//
@@ -646,7 +646,7 @@ object Erasure {
646646
if (paramAdaptationNeeded || resultAdaptationNeeded) {
647647
val bridgeType =
648648
if (paramAdaptationNeeded) {
649-
if (resultAdaptationNeeded) sam.info
649+
if (resultAdaptationNeeded) sam
650650
else implType.derivedLambdaType(paramInfos = samParamTypes)
651651
} else implType.derivedLambdaType(resType = samResultType)
652652
val bridge = ctx.newSymbol(ctx.owner, AdaptedClosureName(meth.symbol.name.asTermName), Flags.Synthetic | Flags.Method, bridgeType)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
482482
false
483483
case argtpe =>
484484
def SAMargOK = formal match {
485-
case SAMType(meth) => argtpe <:< meth.info.toFunctionType()
485+
case SAMType(sam) => argtpe <:< sam.toFunctionType()
486486
case _ => false
487487
}
488488
isCompatible(argtpe, formal) || ctx.mode.is(Mode.ImplicitsEnabled) && SAMargOK

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,10 @@ class Typer extends Namer
740740
// this can type the greatest set of admissible closures.
741741
val funType = pt.dealias
742742
(funType.argTypesLo.init, typeTree(funType.argTypesHi.last))
743-
case SAMType(meth) =>
744-
val mt @ MethodTpe(_, formals, restpe) = meth.info
743+
case SAMType(sam @ MethodTpe(_, formals, restpe)) =>
745744
(formals,
746-
if (mt.isResultDependent)
747-
untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))
745+
if (sam.isResultDependent)
746+
untpd.DependentTypeTree(syms => restpe.substParams(sam, syms.map(_.termRef)))
748747
else
749748
typeTree(restpe))
750749
case tp: TypeParamRef =>
@@ -936,8 +935,8 @@ class Typer extends Namer
936935
meth1.tpe.widen match {
937936
case mt: MethodType =>
938937
pt match {
939-
case SAMType(meth)
940-
if !defn.isFunctionType(pt) && mt <:< meth.info =>
938+
case SAMType(sam)
939+
if !defn.isFunctionType(pt) && mt <:< sam =>
941940
if (!isFullyDefined(pt, ForceDegree.all))
942941
ctx.error(ex"result type of closure is an underspecified SAM type $pt", tree.pos)
943942
TypeTree(pt)
@@ -2406,8 +2405,8 @@ class Typer extends Namer
24062405
case closure(Nil, id @ Ident(nme.ANON_FUN), _)
24072406
if defn.isFunctionType(wtp) && !defn.isFunctionType(pt) =>
24082407
pt match {
2409-
case SAMType(meth)
2410-
if wtp <:< meth.info.toFunctionType() =>
2408+
case SAMType(sam)
2409+
if wtp <:< sam.toFunctionType() =>
24112410
// was ... && isFullyDefined(pt, ForceDegree.noBottom)
24122411
// but this prevents case blocks from implementing polymorphic partial functions,
24132412
// since we do not know the result parameter a priori. Have to wait until the

0 commit comments

Comments
 (0)