From 97f7aa992f856ef7511e59f91b12fb88e21d4d55 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 16 Sep 2024 12:14:00 +0200 Subject: [PATCH] Add debug code --- compiler/src/dotty/tools/dotc/core/Types.scala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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)