From daf1f93ed1dde06af5460d552e55aaa151a15f69 Mon Sep 17 00:00:00 2001 From: marc Date: Wed, 1 Feb 2017 14:53:05 -0800 Subject: [PATCH 1/2] Union unapply method does not disable match exhaustiveness checking --- .../courier/generator/UnionGeneratorTest.scala | 13 +++++++++++++ .../coursera/courier/templates/UnionClass.scala.txt | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scala/generator-test/src/test/scala/org/coursera/courier/generator/UnionGeneratorTest.scala b/scala/generator-test/src/test/scala/org/coursera/courier/generator/UnionGeneratorTest.scala index 9b8f1650..74f8b94e 100644 --- a/scala/generator-test/src/test/scala/org/coursera/courier/generator/UnionGeneratorTest.scala +++ b/scala/generator-test/src/test/scala/org/coursera/courier/generator/UnionGeneratorTest.scala @@ -155,4 +155,17 @@ class UnionGeneratorTest extends GeneratorTest with SchemaFixtures { def testUnionTyperefSchema(): Unit = { assert(TypedDefinition.TYPEREF_SCHEMA.getDereferencedDataSchema === TypedDefinition.SCHEMA) } + + @Test + def testMemberUnapplyReturnsSomeType(): Unit = { + // If the member unapply methods return Option[X] instead of Some[X], then the scala compiler + // turns off match exhaustivity checking for match statements that use the member unapply + // methods. This test asserts that member unapply methods return Some[X], so that we get better + // exhaustivity checking for match statements involving courier unions. + assertCompiles(""" + val recordMember = WithComplexTypesUnion.Union.EmptyMember(Empty()) + WithComplexTypesUnion.Union.EmptyMember.unapply(recordMember): Some[Empty] + """) + } + } diff --git a/scala/generator/src/main/twirl/org/coursera/courier/templates/UnionClass.scala.txt b/scala/generator/src/main/twirl/org/coursera/courier/templates/UnionClass.scala.txt index 74f2908c..f4f273e2 100644 --- a/scala/generator/src/main/twirl/org/coursera/courier/templates/UnionClass.scala.txt +++ b/scala/generator/src/main/twirl/org/coursera/courier/templates/UnionClass.scala.txt @@ -148,7 +148,7 @@ object @(union.scalaType) extends UnionCompanion[@(union.scalaType)] @(if(union. new @(member.classDefinition.memberName)(dataMap) } - def unapply(member: @(member.classDefinition.memberName)): Option[@(member.classDefinition.scalaTypeFullname)] = { + def unapply(member: @(member.classDefinition.memberName)): Some[@(member.classDefinition.scalaTypeFullname)] = { Some(member.value) } From 2ec07beac99a51d71fe1b4816c6d0eb1124acc4a Mon Sep 17 00:00:00 2001 From: marc Date: Fri, 31 Mar 2017 08:27:05 -0700 Subject: [PATCH 2/2] bump version --- gradle-plugin/gradle.properties | 2 +- maven-plugin/pom.xml | 2 +- version.sbt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle-plugin/gradle.properties b/gradle-plugin/gradle.properties index 2ab876da..d782d221 100644 --- a/gradle-plugin/gradle.properties +++ b/gradle-plugin/gradle.properties @@ -1,2 +1,2 @@ -courierVersion=2.0.8 +courierVersion=2.0.10 scalaMajorVersion=2.11 diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index 0a866bb7..a39107d1 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -35,7 +35,7 @@ UTF-8 2.11 2.11.5 - 2.0.8 + 2.0.10 1.7 http://github.com/coursera/courier diff --git a/version.sbt b/version.sbt index d43d810c..ce59af07 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "2.0.8" +version in ThisBuild := "2.0.10"