Skip to content

Commit

Permalink
Merge pull request #46 from coursera/mr-union-unapply-compatible-with…
Browse files Browse the repository at this point in the history
…-exhaustiveness-checking

Union unapply method does not disable match exhaustiveness checking
  • Loading branch information
marcgrr committed Mar 31, 2017
2 parents 8a2cd1e + 517d331 commit fe4f9ee
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
courierVersion=2.0.9
courierVersion=2.0.10
scalaMajorVersion=2.11
2 changes: 1 addition & 1 deletion maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scalaMajorVersion>2.11</scalaMajorVersion>
<scalaVersion>2.11.5</scalaVersion>
<courierVersion>2.0.9</courierVersion>
<courierVersion>2.0.10</courierVersion>
<javaVersion>1.7</javaVersion>
</properties>
<url>http://github.com/coursera/courier</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
""")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "2.0.9"
version in ThisBuild := "2.0.10"

0 comments on commit fe4f9ee

Please sign in to comment.