Skip to content

Commit 2dce908

Browse files
committed
Cleanup of Signature matching
Eliminate sameParams, add comments. Also, minor cleanups elsewhere.
1 parent 5a612a3 commit 2dce908

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/dotty/tools/dotc/config/Config.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ object Config {
7777
*/
7878
final val checkProjections = false
7979

80-
/** If this flag is set it is checked that &/| only apply to types
80+
/** If this flag is set, it is checked that &/| only apply to types
8181
* that are either both hk types or both * types. Should be used
82-
* only for debugging as there a generic class without arguments
83-
* can be produced in an And by Implicits.liftToClasses.
82+
* only for debugging as the assertion may be violated by Implicits.liftToClasses,
83+
* which can produce an And over a generic class without arguments.
8484
*/
8585
final val checkKinds = false
8686

src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
473473
for {
474474
(poly, entries) <- boundsMap.toList
475475
n <- 0 until paramCount(entries)
476-
if true || isBounds(entries(n))
476+
if isBounds(entries(n))
477477
} yield PolyParam(poly, n)
478478

479479
def forallParams(p: PolyParam => Boolean): Boolean = {

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,40 @@ import TypeErasure.sigName
2222
* "scala.String".toTypeName)
2323
*
2424
* The signatures of non-method types are always `NotAMethod`.
25+
*
26+
* There are three kinds of "missing" parts of signatures:
27+
*
28+
* - tpnme.EMPTY Result type marker for NotAMethod and OverloadedSignature
29+
* - tpnme.WILDCARD Arises from a Wildcard or error type
30+
* - tpnme.Uninstantiated Arises from an uninstantiated type variable
2531
*/
2632
case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
2733
import Signature._
2834

29-
/** Does this signature coincide with that signature on their parameter parts? */
30-
final def sameParams(that: Signature): Boolean = this.paramsSig == that.paramsSig
35+
/** Two names are consistent if they are the same or one of them is tpnme.Uninstantiated */
36+
private def consistent(name1: TypeName, name2: TypeName) =
37+
name1 == name2 || name1 == tpnme.Uninstantiated || name2 == tpnme.Uninstantiated
3138

3239
/** Does this signature coincide with that signature on their parameter parts?
3340
* This is the case if all parameter names are _consistent_, i.e. they are either
3441
* equal or on of them is tpnme.Uninstantiated.
3542
*/
3643
final def consistentParams(that: Signature): Boolean = {
37-
def consistent(name1: TypeName, name2: TypeName) =
38-
name1 == name2 || name1 == tpnme.Uninstantiated || name2 == tpnme.Uninstantiated
3944
def loop(names1: List[TypeName], names2: List[TypeName]): Boolean =
4045
if (names1.isEmpty) names2.isEmpty
4146
else names2.nonEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
4247
loop(this.paramsSig, that.paramsSig)
4348
}
4449

4550
/** The degree to which this signature matches `that`.
46-
* If both parameter and result type names match (i.e. they are the same
51+
* If parameter names are consistent and result types names match (i.e. they are the same
4752
* or one is a wildcard), the result is `FullMatch`.
48-
* If only the parameter names match, the result is `ParamMatch` before erasure and
53+
* If only the parameter names are constistent, the result is `ParamMatch` before erasure and
4954
* `NoMatch` otherwise.
50-
* If the parameters do not match, the result is always `NoMatch`.
55+
* If the parameters are inconsistent, the result is always `NoMatch`.
5156
*/
5257
final def matchDegree(that: Signature)(implicit ctx: Context): MatchDegree =
53-
if (sameParams(that))
58+
if (consistentParams(that))
5459
if (resSig == that.resSig || isWildcard(resSig) || isWildcard(that.resSig)) FullMatch
5560
else if (!ctx.erasedTypes) ParamMatch
5661
else NoMatch

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
431431
case tp2 @ MethodType(_, formals2) =>
432432
def compareMethod = tp1 match {
433433
case tp1 @ MethodType(_, formals1) =>
434-
(tp1.signature sameParams tp2.signature) &&
434+
(tp1.signature consistentParams tp2.signature) &&
435435
matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
436436
tp1.isImplicit == tp2.isImplicit && // needed?
437437
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
@@ -442,7 +442,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
442442
case tp2: PolyType =>
443443
def comparePoly = tp1 match {
444444
case tp1: PolyType =>
445-
(tp1.signature sameParams tp2.signature) &&
445+
(tp1.signature consistentParams tp2.signature) &&
446446
matchingTypeParams(tp1, tp2) &&
447447
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
448448
case _ =>

0 commit comments

Comments
 (0)