forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#5845 from adriaanm/t10261
Actually retract clashing synthetic apply/unapply
- Loading branch information
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
trait Companion[T] { | ||
def parse(value: String): Option[T] | ||
def apply(value: String): T = parse(value).get | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scala.util.Try | ||
|
||
object C extends Companion[C] { | ||
def parse(v: String) = if (v.nonEmpty) Some(new C(v)) else None | ||
} | ||
|
||
case class C(value: String) | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
assert(Try{C("")}.isFailure, "Empty value should fail to parse") // check that parse is used to validate input | ||
assert(C("a").value == "a", "Unexpected value") | ||
} | ||
} |