From 7d9425110852205eb2d24126aac00867fbec127f Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Tue, 9 Feb 2016 14:55:30 +0100 Subject: [PATCH] Also include private vals --- compile/api/src/main/scala/xsbt/api/HashAPI.scala | 10 +++++----- .../test/scala/xsbt/api/NameHashingSpecification.scala | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compile/api/src/main/scala/xsbt/api/HashAPI.scala b/compile/api/src/main/scala/xsbt/api/HashAPI.scala index 02cc6aded..0f0baac56 100644 --- a/compile/api/src/main/scala/xsbt/api/HashAPI.scala +++ b/compile/api/src/main/scala/xsbt/api/HashAPI.scala @@ -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) } /** diff --git a/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala b/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala index 470254dda..5d75708dd 100644 --- a/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala +++ b/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala @@ -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) }