Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.coursera.records.test.Empty
import org.coursera.records.test.Empty2
import org.coursera.records.test.InlineOptionalRecord
import org.coursera.records.test.InlineRecord
import org.coursera.records.test.Message
import org.coursera.records.test.Simple
import org.coursera.records.test.SimpleMap
import org.coursera.records.test.WithComplexTypeDefaults
Expand Down Expand Up @@ -470,4 +471,17 @@ class RecordGeneratorTest extends GeneratorTest with SchemaFixtures {
// Fortunately, nothing should depend solely on hashCode() for determining whether two
// records match.
}

@Test
def testUnapplyReturnsSomeType(): Unit = {
// If the unapply method returns Option[X] instead of Some[X], then the scala compiler turns
// off match exhaustivity checking for match statements that use the unapply method. This test
// This test asserts that the unapply method returns Some[X], so that we get better
// exhaustivity checking for match statements involving courier records.
assertCompiles("""
val record = Message("hello", "hello world")
Message.unapply(record): Some[(String, String)]
""")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,8 @@ object @(record.scalaType) extends RecordCompanion[@(record.scalaType)] {
def unapply(record: @(record.scalaType)): Boolean = true
}
case i if i <= 22 => { @* Scala tuples only exist up to Tuple22. *@
def unapply(record: @(record.scalaType)): Option[(@(record.fieldsAsTypeParams))] = {
try {
Some((@(record.prefixedFieldParams("record."))))
} catch {
case cast: TemplateOutputCastException => None
case notPresent: RequiredFieldNotPresentException => None
}
def unapply(record: @(record.scalaType)): Some[(@(record.fieldsAsTypeParams))] = {
Some((@(record.prefixedFieldParams("record."))))
}
}
case _ => {
Expand Down