Skip to content

Commit 5bff0ce

Browse files
committed
Make MatchDegree an enum
1 parent ee1eadb commit 5bff0ce

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ object Denotations {
757757

758758
def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation = {
759759
val situated = if (site == NoPrefix) this else asSeenFrom(site)
760-
val matches = sig.matchDegree(situated.signature) >=
761-
(if (relaxed) Signature.ParamMatch else Signature.FullMatch)
760+
val matches = sig.matchDegree(situated.signature).ordinal >=
761+
(if (relaxed) Signature.ParamMatch else Signature.FullMatch).ordinal
762762
if (matches) this else NoDenotation
763763
}
764764

@@ -1096,7 +1096,7 @@ object Denotations {
10961096
d == Signature.FullMatch &&
10971097
!infoOrCompleter.isInstanceOf[PolyType] && !other.infoOrCompleter.isInstanceOf[PolyType]
10981098
||
1099-
d >= Signature.ParamMatch && info.matches(other.info))
1099+
d != Signature.NoMatch && info.matches(other.info))
11001100
}
11011101

11021102
def mapInherited(ownDenots: PreDenotation, prevDenots: PreDenotation, pre: Type)(implicit ctx: Context): SingleDenotation =

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
107107

108108
object Signature {
109109

110-
type MatchDegree = Int
111-
val NoMatch: Int = 0
112-
val ParamMatch: Int = 1
113-
val FullMatch: Int = 2
110+
enum MatchDegree {
111+
case NoMatch, ParamMatch, FullMatch
112+
}
113+
export MatchDegree._
114114

115115
/** The signature of everything that's not a method, i.e. that has
116116
* a type different from PolyType, MethodType, or ExprType.

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,11 +2154,13 @@ object messages {
21542154
val details = if (decl.isRealMethod && previousDecl.isRealMethod) {
21552155
// compare the signatures when both symbols represent methods
21562156
decl.signature.matchDegree(previousDecl.signature) match {
2157-
case Signature.NoMatch =>
2157+
case Signature.MatchDegree.NoMatch =>
2158+
// DOTTY problem: Need to qualify MatchDegree enum vals since otherwise exhaustivity fails.
2159+
// To fix this, we need to export vals under singleton types.
21582160
"" // shouldn't be reachable
2159-
case Signature.ParamMatch =>
2161+
case Signature.MatchDegree.ParamMatch =>
21602162
"have matching parameter types."
2161-
case Signature.FullMatch =>
2163+
case Signature.MatchDegree.FullMatch =>
21622164
i"have the same$nameAnd type after erasure."
21632165
}
21642166
} else ""

0 commit comments

Comments
 (0)