diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 06b21bab6443..b34416a095db 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -610,16 +610,13 @@ object Denotations { */ def signature(sourceLanguage: SourceLanguage)(using Context): Signature = if (isType) Signature.NotAMethod // don't force info if this is a type denotation - else info match { + else info match case info: MethodOrPoly => try info.signature(sourceLanguage) - catch { // !!! DEBUG - case scala.util.control.NonFatal(ex) => - report.echo(s"cannot take signature of $info") - throw ex - } + catch case ex: Exception => + if ctx.debug then report.echo(s"cannot take signature of $info") + throw ex case _ => Signature.NotAMethod - } def derivedSingleDenotation(symbol: Symbol, info: Type, pre: Type = this.prefix, isRefinedMethod: Boolean = this.isRefinedMethod)(using Context): SingleDenotation = if ((symbol eq this.symbol) && (info eq this.info) && (pre eq this.prefix) && (isRefinedMethod == this.isRefinedMethod)) this diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index f7c7bfa2f8a1..ad32af71fc0d 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -102,18 +102,15 @@ object RefChecks { withMode(Mode.CheckBoundsOrSelfType) { val cinfo = cls.classInfo - def checkSelfConforms(other: ClassSymbol, category: String, relation: String) = + def checkSelfConforms(other: ClassSymbol) = val otherSelf = other.declaredSelfTypeAsSeenFrom(cls.thisType) if otherSelf.exists then if !(cinfo.selfType <:< otherSelf) then - report.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other), + report.error(DoesNotConformToSelfType("illegal inheritance", cinfo.selfType, cls, otherSelf, "parent", other), cls.srcPos) for psym <- parents do - checkSelfConforms(psym.asClass, "illegal inheritance", "parent") - for reqd <- cls.asClass.givenSelfType.classSymbols do - if reqd != cls then - checkSelfConforms(reqd, "missing requirement", "required") + checkSelfConforms(psym.asClass) } end checkSelfAgainstParents diff --git a/tests/neg/i16407.check b/tests/neg/i16407.check new file mode 100644 index 000000000000..5c6bd19ca8c1 --- /dev/null +++ b/tests/neg/i16407.check @@ -0,0 +1,12 @@ +-- Error: tests/neg/i16407.scala:2:2 ----------------------------------------------------------------------------------- +2 | f(g()) // error // error + | ^ + | cannot resolve reference to type (X.this : Y & X).A + | the classfile defining the type might be missing from the classpath + | or the self type of (X.this : Y & X) might not contain all transitive dependencies +-- Error: tests/neg/i16407.scala:2:4 ----------------------------------------------------------------------------------- +2 | f(g()) // error // error + | ^ + | cannot resolve reference to type (X.this : Y & X).A + | the classfile defining the type might be missing from the classpath + | or the self type of (X.this : Y & X) might not contain all transitive dependencies diff --git a/tests/neg/i16407.scala b/tests/neg/i16407.scala new file mode 100644 index 000000000000..ff7192390eef --- /dev/null +++ b/tests/neg/i16407.scala @@ -0,0 +1,11 @@ +trait X { self: Y => + f(g()) // error // error +} +trait Y { self: Z => + type B = A + def f(a: B): Unit = () + def g(): A = ??? +} +trait Z { + type A +} diff --git a/tests/neg/selfInheritance.scala b/tests/neg/selfInheritance.scala index 073316de008c..e8eb2bab5624 100644 --- a/tests/neg/selfInheritance.scala +++ b/tests/neg/selfInheritance.scala @@ -26,7 +26,3 @@ object Test { object M extends C // error: illegal inheritance: self type Test.M.type of object M$ does not conform to self type B of parent class C } - -trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y -trait Y { self: Z => } -trait Z diff --git a/tests/pos/i16407.scala b/tests/pos/i16407.scala new file mode 100644 index 000000000000..8529f81a29af --- /dev/null +++ b/tests/pos/i16407.scala @@ -0,0 +1,7 @@ +trait X { //missing requirement: self type Z[?] & X of trait X does not conform to self type Z[X.this.A] of required trait Z + self: Z[_] => +} + +trait Z[A] extends X { + self: Z[A] => // comment this to compile successfully +} \ No newline at end of file diff --git a/tests/pos/open-selftype.scala b/tests/pos/open-selftype.scala new file mode 100644 index 000000000000..e834f405ec7f --- /dev/null +++ b/tests/pos/open-selftype.scala @@ -0,0 +1,8 @@ + +trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y +trait Y { self: Z => } +trait Z + +package squants: + trait Quantity[A <: Quantity[A]] { self: A => } + trait TimeDerivative[A <: Quantity[A]] { self: Quantity[_] => } \ No newline at end of file