@@ -5942,41 +5942,22 @@ object Types extends TypeUtils {
5942
5942
approxWildcardArgs(tp)
5943
5943
end samParent
5944
5944
5945
+ def isSamClass (tp : Type , cls : ClassSymbol )(using Context ): Boolean =
5946
+ def takesNoArgs (tp : Type ) =
5947
+ ! cls.primaryConstructor.exists // `ContextFunctionN` does not have constructors
5948
+ || tp.applicableConstructors(Nil , adaptVarargs = true ).nonEmpty
5949
+ val noArgsNeeded : Boolean =
5950
+ takesNoArgs(tp) && (! cls.is(Trait ) || takesNoArgs(tp.parents.head))
5951
+ def isInstantiable =
5952
+ val cinfo = cls.classInfo
5953
+ ! cls.isOneOf(FinalOrSealed ) && (cinfo.appliedRef <:< cinfo.selfType)
5954
+ noArgsNeeded && isInstantiable
5955
+
5945
5956
def samClass (tp : Type )(using Context ): Symbol = tp match
5946
- case tp : ClassInfo =>
5947
- val cls = tp.cls
5948
- def zeroParamsOLD (tp : Type ): Boolean = tp.stripPoly match
5949
- case mt : MethodType => mt.paramInfos.isEmpty && ! mt.resultType.isInstanceOf [MethodType ]
5950
- case et : ExprType => true
5951
- case _ => false
5952
- val validCtorOLD =
5953
- val ctor = cls.primaryConstructor
5954
- // `ContextFunctionN` does not have constructors
5955
- ! ctor.exists || zeroParamsOLD(ctor.info)
5956
-
5957
- def takesNoArgs (tp : Type ) =
5958
- ! tp.classSymbol.primaryConstructor.exists // `ContextFunctionN` does not have constructors
5959
- || tp.applicableConstructors(Nil , adaptVarargs = true ).nonEmpty
5960
- def firstParentCls = tp.parents.head.classSymbol
5961
- val noArgsNeeded : Boolean =
5962
- takesNoArgs(tp)
5963
- && (! tp.cls.is(Trait ) || takesNoArgs(tp.parents.head))
5964
-
5965
- if noArgsNeeded != validCtorOLD then
5966
- println(
5967
- i """ SAM change for $tp with parent ${firstParentCls.fullName}, now $noArgsNeeded
5968
- |takesNoArgs: ${takesNoArgs(tp)}
5969
- |takesNoArgsParent: ${takesNoArgs(tp.cls.info.parents.head)}
5970
- |primary: ${firstParentCls.primaryConstructor.info}""" )
5971
-
5972
- def isInstantiable =
5973
- ! tp.cls.isOneOf(FinalOrSealed ) && (tp.appliedRef <:< tp.selfType)
5974
- if noArgsNeeded && isInstantiable then tp.cls
5975
- else NoSymbol
5976
- case tp : AppliedType =>
5977
- samClass(tp.superType)
5978
- case tp : TypeRef =>
5979
- samClass(tp.underlying)
5957
+ case tp : (AppliedType | TypeRef ) =>
5958
+ tp.typeSymbol match
5959
+ case cls : ClassSymbol => if isSamClass(tp, cls) then cls else NoSymbol
5960
+ case _ => samClass(tp.superType)
5980
5961
case tp : RefinedType =>
5981
5962
samClass(tp.underlying)
5982
5963
case tp : TypeBounds =>
0 commit comments