Skip to content

Commit

Permalink
Fix macro crash when handling sealed case classes (com-lihaoyi#634)
Browse files Browse the repository at this point in the history
Fixes com-lihaoyi#628

Sealed classes can be instantiated directly. Therefore, when generating
the typeTag, I included the sealed class itself. This ensures that the
macro correctly handles sealed classes without subclasses. To check
whether it’s a sealed class and not a trait or abstract class, I used
the following condition:
 ```
 sealedParents.find(_ == tpe.typeSymbol)
```
Since `trait` and `abstract class` cannot be instantiated, I believe this approach works. However, I could also explicitly check that the symbol is not a trait or an abstract class, if needed.

What do you think?

remove unused

wip

make scala2 works

Delete some files

Add more tests

more tests

scala3 writer

fix

polish

clean up

Add helper function

scala3 macro

readers

fix bug

test pass

polish

polish

wip

Add Float32 and Float64 to Msg conversions (com-lihaoyi#613)

Small change to include `Float32` and `Float64` conversions in the `Msg`
class. Currently there is no way to extract floats from `Msg` without a
cast at the call site.

Co-authored-by: Li Haoyi <[email protected]>

Update .mill-version (com-lihaoyi#627)

Update and rename build.sc to build.mill (com-lihaoyi#640)

fix

remove unused

Use ListBuffer to preserve orders

polish
  • Loading branch information
nox213 committed Dec 7, 2024
1 parent 942acf4 commit 7602d4d
Show file tree
Hide file tree
Showing 16 changed files with 772 additions and 326 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '17']
java: ['11', '17']
env:
JAVA_OPTS: "-Xss10M"
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '17']
java: ['11', '17']
env:
JAVA_OPTS: "-Xss10M"
steps:
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '17']
java: ['11', '17']
env:
JAVA_OPTS: "-Xss10M"
steps:
Expand All @@ -78,7 +78,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
- name: Check Binary Compatibility
run: ./mill -i -k __.mimaReportBinaryIssues

Expand All @@ -102,7 +102,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
- name: Publish to Maven Central
run: |
if [[ $(git tag --points-at HEAD) != '' ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.11
0.12.0
3 changes: 3 additions & 0 deletions build.sc → build.mill
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package build
// plugins
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.1.1`
Expand Down Expand Up @@ -153,6 +154,7 @@ object upack extends Module {
def moduleDeps = Seq(upickle.core.jvm())
object test extends CommonTestModule{
def moduleDeps = super.moduleDeps ++ Seq(ujson.jvm().test, upickle.core.jvm().test)
def forkEnv = super.forkEnv() ++ Map("EXAMPLE_JSON" -> exampleJson().path.toString)
}
}

Expand Down Expand Up @@ -182,6 +184,7 @@ object ujson extends Module{

object test extends CommonTestModule{
def moduleDeps = super.moduleDeps ++ Seq(upickle.core.jvm().test)
def forkEnv = super.forkEnv() ++ Map("EXAMPLE_JSON" -> exampleJson().path.toString)
}
}

Expand Down
6 changes: 4 additions & 2 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set -e

if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
DEFAULT_MILL_VERSION=0.11.2
DEFAULT_MILL_VERSION=0.11.12
fi

if [ -z "$MILL_VERSION" ] ; then
Expand Down Expand Up @@ -53,7 +53,9 @@ if [ -z "$MILL_MAIN_CLI" ] ; then
fi

MILL_FIRST_ARG=""
if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then

# first arg is a long flag for "--interactive" or starts with "-i"
if [ "$1" = "--bsp" ] || [ "${1#"-i"}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
# Need to preserve the first position of those listed options
MILL_FIRST_ARG=$1
shift
Expand Down
7 changes: 4 additions & 3 deletions ujson/test/src-jvm/ujson/ExampleJsonTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import java.nio.file.{Files, Paths}
import utest._

object ExampleJsonTests extends TestSuite {
def check(name: String) = {
TestUtil.checkParse(new String(Files.readAllBytes(Paths.get("exampleJson", name))), true)
}
def check(name: String) = TestUtil.checkParse(
new String(Files.readAllBytes(Paths.get(sys.env("EXAMPLE_JSON"), name))),
true
)
val tests = Tests {
test - check("australia-abc.json")
test - check("bitcoin.json")
Expand Down
18 changes: 18 additions & 0 deletions upack/src/upack/Msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ sealed trait Msg extends Readable with geny.Writable{
case UInt64(value) => value
case _ => throw Msg.InvalidData(this, "Expected ujson.Num")
}
/**
* Returns the `Float` value of this [[Msg]], fails if it is not
* a [[upack.Float32]] or [[upack.Float64]]
*/
def float32 = this match{
case Float32(value) => value
case Float64(value) => value.toFloat
case _ => throw Msg.InvalidData(this, "Expected ujson.Num")
}
/**
* Returns the `Double` value of this [[Msg]], fails if it is not
* a [[upack.Float32]] or [[upack.Float64]]
*/
def float64 = this match{
case Float32(value) => value.toDouble
case Float64(value) => value
case _ => throw Msg.InvalidData(this, "Expected ujson.Num")
}
/**
* Returns the `Boolean` value of this [[Msg]], fails if it is not
* a [[upack.Bool]]
Expand Down
2 changes: 1 addition & 1 deletion upack/test/src-jvm/upack/ExampleJsonTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import utest._
object ExampleJsonTests extends TestSuite {
def check(name: String) = {
val msgPack = ujson
.read(Files.readAllBytes(Paths.get("exampleJson", name)))
.read(Files.readAllBytes(Paths.get(sys.env("EXAMPLE_JSON"), name)))
.transform(new MsgPackWriter(new java.io.ByteArrayOutputStream))
.toByteArray
TestUtil.checkParse(msgPack, true)
Expand Down
7 changes: 4 additions & 3 deletions upack/test/src-jvm/upack/MsgPackJvmTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ object MsgPackJvmTests extends TestSuite{

// Taken from:
// https://github.com/msgpack/msgpack-ruby/tree/a22d8268f82e0f2ae95f038285af43ce5971810e/spec
val casesJson = "upack/test/resources/cases.json"
val casesMsg = "upack/test/resources/cases.msg"
val casesCompactMsg = "upack/test/resources/cases_compact.msg"
val resources = sys.env("MILL_TEST_RESOURCE_DIR")
val casesJson = resources + "/cases.json"
val casesMsg = resources + "/cases.msg"
val casesCompactMsg = resources + "/cases_compact.msg"
val expectedJson = ujson.read(readBytes(casesJson))
// println("---msgs---")
val msg = readMsgs(casesMsg)
Expand Down
Loading

0 comments on commit 7602d4d

Please sign in to comment.