Skip to content

Commit 766ab48

Browse files
committed
Drop FromDigits support due to it being removed from Scala 3.0 final
1 parent ae8ee45 commit 766ab48

File tree

7 files changed

+45
-119
lines changed

7 files changed

+45
-119
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
os: [ubuntu-latest]
29-
scala: [2.11.12, 2.12.11, 2.13.3, 3.0.0-M3, 3.0.0-RC1]
29+
scala: [2.11.12, 2.12.11, 2.13.3, 3.0.0-RC1]
3030
3131
runs-on: ${{ matrix.os }}
3232
steps:
@@ -55,13 +55,7 @@ jobs:
5555
- name: Check that workflows are up to date
5656
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
5757

58-
- run: sbt ++${{ matrix.scala }} compile
59-
60-
- run: sbt ++${{ matrix.scala }} coreJVM/test
61-
62-
- run: sbt ++${{ matrix.scala }} coreJS/test
63-
64-
- run: sbt ++${{ matrix.scala }} +mimaReportBinaryIssues
58+
- run: sbt ++${{ matrix.scala }} ci
6559

6660
- name: Compress target directories
6761
run: tar cf targets.tar target core/jvm/target core/js/target benchmark/target project/target
@@ -135,16 +129,6 @@ jobs:
135129
tar xf targets.tar
136130
rm targets.tar
137131
138-
- name: Download target directories (3.0.0-M3)
139-
uses: actions/download-artifact@v2
140-
with:
141-
name: target-${{ matrix.os }}-3.0.0-M3-${{ matrix.java }}
142-
143-
- name: Inflate target directories (3.0.0-M3)
144-
run: |
145-
tar xf targets.tar
146-
rm targets.tar
147-
148132
- name: Download target directories (3.0.0-RC1)
149133
uses: actions/download-artifact@v2
150134
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ project/plugins/project/
1313
.metals
1414
project/metals.sbt
1515
.bsp
16+
.vscode
17+
project/project

build.sbt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ ThisBuild / organizationName := "Scodec"
1313
ThisBuild / homepage := Some(url("https://github.com/scodec/scodec-bits"))
1414
ThisBuild / startYear := Some(2013)
1515

16-
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.11", "2.13.3", "3.0.0-M3", "3.0.0-RC1")
16+
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.11", "2.13.3", "3.0.0-RC1")
1717

1818
ThisBuild / strictSemVer := false
1919

2020
ThisBuild / versionIntroduced := Map(
21-
"3.0.0-M3" -> "1.1.99",
22-
"3.0.0-M2" -> "1.1.99",
2321
"2.13" -> "1.1.12",
2422
"2.12" -> "1.1.2",
2523
"2.11" -> "1.1.99" // Ignore 2.11 in mima
@@ -31,13 +29,6 @@ ThisBuild / spiewakCiReleaseSnapshots := true
3129

3230
ThisBuild / spiewakMainBranches := List("main")
3331

34-
ThisBuild / githubWorkflowBuild := Seq(
35-
WorkflowStep.Sbt(List("compile")),
36-
WorkflowStep.Sbt(List("coreJVM/test")),
37-
WorkflowStep.Sbt(List("coreJS/test")),
38-
WorkflowStep.Sbt(List("+mimaReportBinaryIssues"))
39-
)
40-
4132
ThisBuild / scmInfo := Some(
4233
ScmInfo(url("https://github.com/scodec/scodec-bits"), "[email protected]:scodec/scodec-bits.git")
4334
)

core/shared/src/main/scala-3/scodec/bits/BitVectorPlatform.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030

3131
package scodec.bits
3232

33-
import scala.util.FromDigits
33+
// import scala.util.FromDigits
3434

3535
private[bits] trait BitVectorPlatform { self: BitVector.type =>
36+
/* Disabled because FromDigits is only available in scalac snapshots/nightlies as of https://github.com/lampepfl/dotty/pull/11852
3637
given FromDigits.WithRadix[BitVector] with {
3738
def fromDigits(digits: String, radix: Int): BitVector = radix match {
3839
case 16 => ByteVector.fromValidHex(digits).bits
3940
case _ => ByteVector.fromValidHex(new java.math.BigInteger(digits, radix).toString(16)).bits
4041
}
4142
}
43+
*/
4244
}

core/shared/src/main/scala-3/scodec/bits/ByteVectorPlatform.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030

3131
package scodec.bits
3232

33-
import scala.util.FromDigits
33+
// import scala.util.FromDigits
3434

3535
private[bits] trait ByteVectorPlatform { self: ByteVector.type =>
36+
/* Disabled because FromDigits is only available in scalac snapshots/nightlies as of https://github.com/lampepfl/dotty/pull/11852
3637
given FromDigits.WithRadix[ByteVector] with {
3738
def fromDigits(digits: String, radix: Int): ByteVector =
3839
radix match {
3940
case 16 => ByteVector.fromValidHex(digits)
4041
case _ => ByteVector.fromValidHex(new java.math.BigInteger(digits, radix).toString(16))
4142
}
4243
}
44+
*/
4345
}

core/shared/src/main/scala-3/scodec/bits/Interpolators.scala

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
package scodec.bits
3232

33-
import scala.quoted._
33+
import scala.quoted.*
3434

3535
/**
3636
* Provides the `hex` string interpolator, which returns `ByteVector` instances from hexadecimal strings.
@@ -41,7 +41,7 @@ import scala.quoted._
4141
* }}}
4242
*/
4343
extension (inline ctx: StringContext) inline def hex (inline args: Any*): ByteVector =
44-
${Literals.validateHex('ctx, 'args)}
44+
${Literals.Hex('ctx, 'args)}
4545

4646
/**
4747
* Provides the `bin` string interpolator, which returns `BitVector` instances from binary strings.
@@ -52,57 +52,41 @@ extension (inline ctx: StringContext) inline def hex (inline args: Any*): ByteVe
5252
* }}}
5353
*/
5454
extension (inline ctx: StringContext) inline def bin (inline args: Any*): BitVector =
55-
${Literals.validateBin('ctx, 'args)}
55+
${Literals.Bin('ctx, 'args)}
5656

57-
object Literals {
57+
object Literals:
5858

59-
trait Validator[A] {
60-
def validate(s: String): Option[String]
61-
def build(s: String)(using Quotes): Expr[A]
62-
}
59+
trait Validator[A]:
60+
def validate(s: String)(using Quotes): Either[String, Expr[A]]
6361

64-
def validateHex(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[ByteVector] =
65-
validate(Hex, strCtxExpr, argsExpr)
66-
67-
def validateBin(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[BitVector] =
68-
validate(Bin, strCtxExpr, argsExpr)
69-
70-
def validate[A](validator: Validator[A], strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[A] = {
71-
strCtxExpr.value match {
72-
case Some(sc) => validate(validator, sc.parts, argsExpr)
73-
case None =>
74-
quotes.reflect.report.error("StringContext args must be statically known")
75-
???
76-
}
77-
}
78-
79-
private def validate[A](validator: Validator[A], parts: Seq[String], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[A] = {
80-
if (parts.size == 1) {
81-
val literal = parts.head
82-
validator.validate(literal) match {
83-
case Some(err) =>
84-
quotes.reflect.report.error(err)
85-
???
62+
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[A] =
63+
strCtxExpr.value match
64+
case Some(sc) => apply(sc.parts, argsExpr)
8665
case None =>
87-
validator.build(literal)
88-
}
89-
} else {
90-
quotes.reflect.report.error("interpolation not supported", argsExpr)
91-
???
92-
}
93-
}
66+
quotes.reflect.report.error("StringContext args must be statically known")
67+
???
9468

95-
object Hex extends Validator[ByteVector] {
96-
def validate(s: String): Option[String] =
97-
ByteVector.fromHex(s).fold(Some("hexadecimal string literal may only contain characters [0-9a-fA-f]"))(_ => None)
98-
def build(s: String)(using Quotes): Expr[ByteVector] =
99-
'{ByteVector.fromValidHex(${Expr(s)})},
100-
}
69+
private def apply(parts: Seq[String], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[A] =
70+
if parts.size == 1 then
71+
val literal = parts.head
72+
validate(literal) match
73+
case Left(err) =>
74+
quotes.reflect.report.error(err)
75+
???
76+
case Right(a) =>
77+
a
78+
else
79+
quotes.reflect.report.error("interpolation not supported", argsExpr)
80+
???
81+
82+
object Hex extends Validator[ByteVector]:
83+
def validate(s: String)(using Quotes): Either[String, Expr[ByteVector]] =
84+
ByteVector.fromHex(s) match
85+
case None => Left("hexadecimal string literal may only contain characters [0-9a-fA-f]")
86+
case Some(_) => Right('{ByteVector.fromValidHex(${Expr(s)})})
10187

102-
object Bin extends Validator[BitVector] {
103-
def validate(s: String): Option[String] =
104-
ByteVector.fromBin(s).fold(Some("binary string literal may only contain characters [0, 1]"))(_ => None)
105-
def build(s: String)(using Quotes): Expr[BitVector] =
106-
'{BitVector.fromValidBin(${Expr(s)})},
107-
}
108-
}
88+
object Bin extends Validator[BitVector]:
89+
def validate(s: String)(using Quotes): Either[String, Expr[BitVector]] =
90+
ByteVector.fromBin(s) match
91+
case None => Left("binary string literal may only contain characters [0, 1]")
92+
case Some(_) => Right('{BitVector.fromValidBin(${Expr(s)})})

core/shared/src/main/scala-3/scodec/bits/package.scala

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)