Skip to content

Commit

Permalink
Revise SAM test
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Sep 16, 2024
1 parent dba3270 commit f13c61f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5963,25 +5963,21 @@ object Types extends TypeUtils {
noArgsNeeded && !mt.resultType.isInstanceOf[MethodType]
case et: ExprType => true
case _ => false
def validCtor(cls: Symbol): Boolean =
val ctor = cls.primaryConstructor
if !ctor.exists then true // `ContextFunctionN` does not have constructors
else if !zeroParams(ctor.info) then false
else if !cls.is(Trait) then true
else
val firstParentCls = cls.info.parents.head.classSymbol
if firstParentCls.isClass && !firstParentCls.is(Trait) then
validCtor(firstParentCls) // need to check class constructor as well
else
true
val validCtorNEW = validCtor(tp.cls)

if validCtorNEW != validCtorOLD then
println(i"SAM change for $tp with parent ${cls.info.parents.head.classSymbol.fullName}, now $validCtorNEW")
def takesNoArgs(tp: Type) =
val constrs = tp.decl(nme.CONSTRUCTOR)
!constrs.exists // `ContextFunctionN` does not have constructors
|| constrs.hasAltWith(constr => zeroParams(constr.info))
def firstParentCls = cls.info.parents.head.classSymbol
val noArgsNeeded: Boolean =
takesNoArgs(tp)
&& (!tp.cls.is(Trait) || takesNoArgs(tp.cls.info.parents.head))

if noArgsNeeded != validCtorOLD then
println(i"SAM change for $tp with parent ${firstParentCls.fullName}, now $noArgsNeeded")

def isInstantiable =
!tp.cls.isOneOf(FinalOrSealed) && (tp.appliedRef <:< tp.selfType)
if validCtorNEW && isInstantiable then tp.cls
if noArgsNeeded && isInstantiable then tp.cls
else NoSymbol
case tp: AppliedType =>
samClass(tp.superType)
Expand Down

0 comments on commit f13c61f

Please sign in to comment.