diff options
author | Martin Odersky <odersky@gmail.com> | 2016-06-30 10:19:00 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-11 13:35:06 +0200 |
commit | 30e15aba1226c940493c9fecd68467d7823f2c3d (patch) | |
tree | 5cdab212e7728b3f6dce36bac64a74766fe982ff /src/dotty/tools/dotc/core/Signature.scala | |
parent | 68abba180ccfbe7f92f0d2cae29aeae92619e054 (diff) | |
download | dotty-30e15aba1226c940493c9fecd68467d7823f2c3d.tar.gz dotty-30e15aba1226c940493c9fecd68467d7823f2c3d.tar.bz2 dotty-30e15aba1226c940493c9fecd68467d7823f2c3d.zip |
Cleanup of Signature matching
Eliminate sameParams, add comments.
Also, minor cleanups elsewhere.
Diffstat (limited to 'src/dotty/tools/dotc/core/Signature.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Signature.scala | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/Signature.scala b/src/dotty/tools/dotc/core/Signature.scala index 984315f18..c0647ad1d 100644 --- a/src/dotty/tools/dotc/core/Signature.scala +++ b/src/dotty/tools/dotc/core/Signature.scala @@ -22,20 +22,25 @@ import TypeErasure.sigName * "scala.String".toTypeName) * * The signatures of non-method types are always `NotAMethod`. + * + * There are three kinds of "missing" parts of signatures: + * + * - tpnme.EMPTY Result type marker for NotAMethod and OverloadedSignature + * - tpnme.WILDCARD Arises from a Wildcard or error type + * - tpnme.Uninstantiated Arises from an uninstantiated type variable */ case class Signature(paramsSig: List[TypeName], resSig: TypeName) { import Signature._ - /** Does this signature coincide with that signature on their parameter parts? */ - final def sameParams(that: Signature): Boolean = this.paramsSig == that.paramsSig + /** Two names are consistent if they are the same or one of them is tpnme.Uninstantiated */ + private def consistent(name1: TypeName, name2: TypeName) = + name1 == name2 || name1 == tpnme.Uninstantiated || name2 == tpnme.Uninstantiated /** Does this signature coincide with that signature on their parameter parts? * This is the case if all parameter names are _consistent_, i.e. they are either * equal or on of them is tpnme.Uninstantiated. */ final def consistentParams(that: Signature): Boolean = { - def consistent(name1: TypeName, name2: TypeName) = - name1 == name2 || name1 == tpnme.Uninstantiated || name2 == tpnme.Uninstantiated def loop(names1: List[TypeName], names2: List[TypeName]): Boolean = if (names1.isEmpty) names2.isEmpty else names2.nonEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail) @@ -43,14 +48,14 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) { } /** The degree to which this signature matches `that`. - * If both parameter and result type names match (i.e. they are the same + * If parameter names are consistent and result types names match (i.e. they are the same * or one is a wildcard), the result is `FullMatch`. - * If only the parameter names match, the result is `ParamMatch` before erasure and + * If only the parameter names are constistent, the result is `ParamMatch` before erasure and * `NoMatch` otherwise. - * If the parameters do not match, the result is always `NoMatch`. + * If the parameters are inconsistent, the result is always `NoMatch`. */ final def matchDegree(that: Signature)(implicit ctx: Context): MatchDegree = - if (sameParams(that)) + if (consistentParams(that)) if (resSig == that.resSig || isWildcard(resSig) || isWildcard(that.resSig)) FullMatch else if (!ctx.erasedTypes) ParamMatch else NoMatch |