Skip to content

Commit

Permalink
Delegate should handle private and protected members correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisNeveu committed Feb 21, 2017
1 parent 83f71ac commit 1c73ff7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions macrame/src/main/scala/macrame/delegate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ object delegate {
val delegatedMembers : List[Tree] = delegateType.members.filter(s
(containerType.member(s.name) == NoSymbol) &&
(s.name.decoded != "<init>") &&
!(delegateType.typeSymbol.asClass.isCaseClass && s.name.decoded == "copy")
!(delegateType.typeSymbol.asClass.isCaseClass && s.name.decoded == "copy") &&
!s.isPrivate &&
!s.isProtected
).collect {
case method : MethodSymbol
val arguments = method.paramss.map(_.map { p
Expand Down Expand Up @@ -167,7 +169,9 @@ object delegate {
!existingMembers.contains(s.name) &&
(containerType.member(s.name) == NoSymbol) &&
(s.name.decoded != "<init>") &&
!(delegateType.typeSymbol.asClass.isCaseClass && s.name.decoded == "copy")
!(delegateType.typeSymbol.asClass.isCaseClass && s.name.decoded == "copy") &&
!s.isPrivate &&
!s.isProtected
).collect {
case method : MethodSymbol
val arguments = method.paramss.map(_.map { p
Expand Down
13 changes: 13 additions & 0 deletions macrame/src/test/scala/macrame/DelegateTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ class DelegateTest extends FunSuite {
"xxx".get
""")
}

test("Delegated parameters should handle private members.") {
final case class Delegate(
headline : Option[String] = None) {
private val foo : Int = 5
private val baz : String = "five"
}
assertCompiles("""
final case class PostContent(
headline : Option[String] = None,
@delegate un : Delegate)
""")
}
}

0 comments on commit 1c73ff7

Please sign in to comment.