Skip to content

Commit

Permalink
Revert "Fix: generate tree eagerly before checking for private constr…
Browse files Browse the repository at this point in the history
…uctors (#2846)" (#2943)

* Revert "Fix: generate tree eagerly before checking for private constructors (#2846)"

This reverts commit b6be983.

* Add test
  • Loading branch information
regadas authored May 11, 2020
1 parent c2f5c13 commit 994469a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ private[coders] object CoderMacros {
imp.map(_ => EmptyTree).getOrElse {
// Magnolia does not support classes with a private constructor.
// Workaround the limitation by using a fallback in that case
val tree = MagnoliaMacros.genWithoutAnnotations[T](c)
privateConstructor(c)(wtt).fold(tree) { _ =>
privateConstructor(c)(wtt).fold(MagnoliaMacros.genWithoutAnnotations[T](c)) { _ =>
q"_root_.com.spotify.scio.coders.Coder.fallback[$wtt](null)"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ object PrivateClass {
def apply(l: Long): PrivateClass = new PrivateClass(l)
}

case class UsesPrivateClass(privateClass: PrivateClass)

case class ClassWithProtoEnum(s: String, enum: OuterClassForProto.EnumExample)

@SerialVersionUID(1)
Expand Down Expand Up @@ -363,6 +365,11 @@ final class CoderTest extends AnyFlatSpec with Matchers {
PrivateClass(42L) coderShould fallback()
}

it should "support classes that contain classes with private constructors" in {
Coder.gen[UsesPrivateClass]
UsesPrivateClass(PrivateClass(1L)) coderShould notFallback()
}

it should "not derive Coders for org.apache.beam.sdk.values.Row" in {
import org.apache.beam.sdk.values.Row
"Coder[Row]" shouldNot compile
Expand Down

0 comments on commit 994469a

Please sign in to comment.