Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should the Record unapply method always return Some? #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcgrr
Copy link
Contributor

@marcgrr marcgrr commented Mar 31, 2017

Similar to #46.

I had a courier record Foo { bar: Bar? } and I used it to write a bug:

foo match {
  case Foo(Some(bar)) => doStuff(bar)
}

The bug is that the match is not exhaustive. The scala exhaustivity checker would have caught this if Foo's generated unapply method had return type Some[Foo] instead of Option[Foo].

Unfortunately, the unapply method in the RecordClass.scala.txt template has some ways of returning None, which I had to remove in order to make this work.

I don't really understand why the catching that used to be there is necessary. Surely when you have an instance of a record, returning all of its fields should always succeed? If that's true, then the catching is not necessary.

(sorry I accidentally closed #54 and I don't know how to reopen it, so this is just a duplicate of #54)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant