diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index b626464bc428..c06b349db3c5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -5944,6 +5944,16 @@ object Types extends TypeUtils { def samClass(tp: Type)(using Context): Symbol = tp match case tp: ClassInfo => + val cls = tp.cls + def zeroParamsOLD(tp: Type): Boolean = tp.stripPoly match + case mt: MethodType => mt.paramInfos.isEmpty && !mt.resultType.isInstanceOf[MethodType] + case et: ExprType => true + case _ => false + val validCtorOLD = + val ctor = cls.primaryConstructor + // `ContextFunctionN` does not have constructors + !ctor.exists || zeroParamsOLD(ctor.info) + def zeroParams(tp: Type): Boolean = tp.stripPoly match case mt: MethodType => val noArgsNeeded = mt.paramInfos match @@ -5957,9 +5967,14 @@ object Types extends TypeUtils { val ctor = cls.primaryConstructor (!ctor.exists || zeroParams(ctor.info)) // `ContextFunctionN` does not have constructors && (!cls.is(Trait) || validCtor(cls.info.parents.head.classSymbol)) + 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 isInstantiable = !tp.cls.isOneOf(FinalOrSealed) && (tp.appliedRef <:< tp.selfType) - if validCtor(tp.cls) && isInstantiable then tp.cls + if validCtorNEW && isInstantiable then tp.cls else NoSymbol case tp: AppliedType => samClass(tp.superType)