This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
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 #433 from jvican/nothing-picklers
Add pickler and unpickler for Nothing
- Loading branch information
Showing
5 changed files
with
44 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,16 @@ | ||
package scala.pickling.pickler | ||
|
||
import scala.pickling._ | ||
import PicklingErrors.NothingIsNotUnpicklable | ||
|
||
trait NothingPicklers { | ||
implicit object NothingPicklerUnpickler extends AbstractPicklerUnpickler[Nothing] { | ||
override def tag: FastTypeTag[Nothing] = FastTypeTag.Nothing | ||
/** Impossible to call in Scala, no value can be typed [[Nothing]] */ | ||
override def pickle(picklee: Nothing, builder: PBuilder): Unit = ??? | ||
/** Don't call [[unpickle]], [[Nothing]] cannot be unpickled. */ | ||
override def unpickle(tag: String, reader: PReader): Any = | ||
throw NothingIsNotUnpicklable | ||
} | ||
} | ||
|
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
23 changes: 23 additions & 0 deletions
23
core/src/test/scala/scala/pickling/runtime/NothingPickleUnpickleTest.scala
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,23 @@ | ||
package scala.pickling.runtime | ||
|
||
import org.scalatest.FunSuite | ||
|
||
import scala.pickling.Defaults._ | ||
import scala.pickling.json._ | ||
|
||
import scala.pickling.AbstractPicklerUnpickler | ||
import scala.pickling.PicklingErrors.NothingIsNotUnpicklable | ||
|
||
class NothingPickleUnpickleTest extends FunSuite { | ||
|
||
val nothingPU = implicitly[AbstractPicklerUnpickler[Nothing]] | ||
|
||
// `pickle` cannot simply be called, only test `unpickle` | ||
test("unpickle `Nothing` throws an exception") { | ||
intercept[NothingIsNotUnpicklable.type] { | ||
val reader = pickleFormat.createReader(JSONPickle("{}")) | ||
nothingPU.unpickle("", reader) | ||
} | ||
} | ||
|
||
} |