Skip to content

Commit f13c61f

Browse files
committed
Revise SAM test
1 parent dba3270 commit f13c61f

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5963,25 +5963,21 @@ object Types extends TypeUtils {
59635963
noArgsNeeded && !mt.resultType.isInstanceOf[MethodType]
59645964
case et: ExprType => true
59655965
case _ => false
5966-
def validCtor(cls: Symbol): Boolean =
5967-
val ctor = cls.primaryConstructor
5968-
if !ctor.exists then true // `ContextFunctionN` does not have constructors
5969-
else if !zeroParams(ctor.info) then false
5970-
else if !cls.is(Trait) then true
5971-
else
5972-
val firstParentCls = cls.info.parents.head.classSymbol
5973-
if firstParentCls.isClass && !firstParentCls.is(Trait) then
5974-
validCtor(firstParentCls) // need to check class constructor as well
5975-
else
5976-
true
5977-
val validCtorNEW = validCtor(tp.cls)
5978-
5979-
if validCtorNEW != validCtorOLD then
5980-
println(i"SAM change for $tp with parent ${cls.info.parents.head.classSymbol.fullName}, now $validCtorNEW")
5966+
def takesNoArgs(tp: Type) =
5967+
val constrs = tp.decl(nme.CONSTRUCTOR)
5968+
!constrs.exists // `ContextFunctionN` does not have constructors
5969+
|| constrs.hasAltWith(constr => zeroParams(constr.info))
5970+
def firstParentCls = cls.info.parents.head.classSymbol
5971+
val noArgsNeeded: Boolean =
5972+
takesNoArgs(tp)
5973+
&& (!tp.cls.is(Trait) || takesNoArgs(tp.cls.info.parents.head))
5974+
5975+
if noArgsNeeded != validCtorOLD then
5976+
println(i"SAM change for $tp with parent ${firstParentCls.fullName}, now $noArgsNeeded")
59815977

59825978
def isInstantiable =
59835979
!tp.cls.isOneOf(FinalOrSealed) && (tp.appliedRef <:< tp.selfType)
5984-
if validCtorNEW && isInstantiable then tp.cls
5980+
if noArgsNeeded && isInstantiable then tp.cls
59855981
else NoSymbol
59865982
case tp: AppliedType =>
59875983
samClass(tp.superType)

0 commit comments

Comments
 (0)