Also include private vals

This commit is contained in:
Martin Duhem 2016-02-09 14:55:30 +01:00
parent 8e17269c97
commit 7d94251108
2 changed files with 8 additions and 8 deletions

View File

@ -151,17 +151,17 @@ final class HashAPI(includePrivate: Boolean, includeParamNames: Boolean, include
def hashDefinitions(ds: Seq[Definition], topLevel: Boolean, isTrait: Boolean): Unit =
{
// If the enclosing definition is a trait, then we must include private vars in the API hash
// of the trait, because scalac will generate setters and getters for these vars in the traits
// If the enclosing definition is a trait, then we must include private vars and vals in the API hash
// of the trait, because scalac will generate setters, getters and fields for them in the traits
// implementors.
val traitPrivateVars =
val traitPrivateFields =
if (!includePrivate && !topLevel && isTrait) {
def isPublic(d: Definition): Boolean = d.access match { case _: xsbti.api.Public => true; case _ => false }
ds.collect { case v: Var if !isPublic(v) => v }
ds.collect { case fl: FieldLike if !isPublic(fl) => fl }
} else Seq.empty
val defs = SameAPI.filterDefinitions(ds, topLevel, includePrivate)
hashSymmetric(traitPrivateVars ++ defs, hashDefinition)
hashSymmetric(traitPrivateFields ++ defs, hashDefinition)
}
/**

View File

@ -177,7 +177,7 @@ class NameHashingSpecification extends Specification {
* we get abstract method errors at runtime, because the types expected by the setter (for instance) does not
* match.
*
* NOTE: This logic is important for vars only. No other private member needs to be included.
* NOTE: This logic is important for vars and vals only. No other private member needs to be included.
*/
"private var in traits are included in API hash" in {
/* trait Foo { private var x } */
@ -199,7 +199,7 @@ class NameHashingSpecification extends Specification {
}
"private vals in traits are NOT included in API hash" in {
"private vals in traits are included in API hash" in {
/* trait Foo { private val x } */
val fooTrait1 =
simpleTrait("Foo",
@ -215,7 +215,7 @@ class NameHashingSpecification extends Specification {
val api1 = new SourceAPI(Array.empty, Array(fooTrait1))
val api2 = new SourceAPI(Array.empty, Array(fooTrait2))
HashAPI(api1) === HashAPI(api2)
HashAPI(api1) !== HashAPI(api2)
}