Skip to content

Commit

Permalink
4.2.8 Fix primative arrays and unit being void
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuckow committed Jun 23, 2020
1 parent 4a94b35 commit 5a20e51
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
4.2.8
-----
2020-06-22

* Fix primative arrays

4.2.7
-----
2020-05-27

* Guice 4.2.3

4.2.6
-----
2020-07-19

* Fix for Singleton types

4.2.5
-----
2019-06-22
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ We currently support Scala `2.11, 2.12, 2.13`
<dependency>
<groupId>net.codingwell</groupId>
<artifactId>scala-guice_2.13</artifactId>
<version>4.2.7</version>
<version>4.2.8</version>
</dependency>
```

##### sbt:
```scala
"net.codingwell" %% "scala-guice" % "4.2.7"
"net.codingwell" %% "scala-guice" % "4.2.8"
```

##### gradle:
```groovy
'net.codingwell:scala-guice_2.13:4.2.7'
'net.codingwell:scala-guice_2.13:4.2.8'
```

### Mixin
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description := "Scala syntax for Guice"

organization := "net.codingwell"

version := "4.2.7"
version := "4.2.8"

licenses := Seq("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))

Expand Down
16 changes: 10 additions & 6 deletions src/main/scala/net/codingwell/scalaguice/TypeConversions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ private [scalaguice] object TypeConversions {

}

def scalaTypeToJavaType(scalaType: ScalaType, mirror: Mirror): JavaType = {
def scalaTypeToJavaType(scalaType: ScalaType, mirror: Mirror, allowPrimative: Boolean = false): JavaType = {
scalaType.dealias match {
case `anyType` => classOf[java.lang.Object]
case ExistentialType(symbols, underlying) => scalaTypeToJavaType(underlying, mirror)
case ArrayType(argType) => arrayOf(scalaTypeToJavaType(argType, mirror))
case ArrayType(argType) => arrayOf(scalaTypeToJavaType(argType, mirror, allowPrimative=true))
case ClassType(symbol, args) => {
val rawType = mirror.runtimeClass(symbol)
val ownerType = findOwnerOf(symbol, mirror)
args.map(arg => scalaTypeToJavaType(arg, mirror)) match {
case Nil => toWrapper(rawType)
case mappedArgs if ownerType.nonEmpty => newParameterizedTypeWithOwner(ownerType.get, rawType, mappedArgs:_*)
case mappedArgs => newParameterizedType(rawType, mappedArgs:_*)
if(symbol == symbolOf[Unit]) {
classOf[scala.runtime.BoxedUnit]
} else {
args.map(arg => scalaTypeToJavaType(arg, mirror)) match {
case Nil => if(allowPrimative) rawType else toWrapper(rawType)
case mappedArgs if ownerType.nonEmpty => newParameterizedTypeWithOwner(ownerType.get, rawType, mappedArgs:_*)
case mappedArgs => newParameterizedType(rawType, mappedArgs:_*)
}
}
}
case WildcardType(lowerBounds, upperBounds) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class ScalaModuleSpec extends WordSpec with Matchers {

//This test needs work to resolve #65
"allow binding by name to Unit" ignore {
try {
val foo:(=> Unit) => String = (a) => "dog"
val module = new AbstractModule with ScalaModule {
override def configure() = {
Expand All @@ -156,6 +157,9 @@ class ScalaModuleSpec extends WordSpec with Matchers {
val injector = Guice.createInjector(module)
val func = injector.instance[(=> Unit) => String]
func shouldEqual foo
} catch {
case e: Throwable => { e.printStackTrace; throw e }
}
}


Expand Down
23 changes: 21 additions & 2 deletions src/test/scala/net/codingwell/scalaguice/TypeLiteralSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ class TypeLiteralSpec extends FunSpec with Matchers {
}

it("should handle type parameters that are arrays") {
typeLiteral[Array[Int]] shouldEqual new TypeLiteral[Array[java.lang.Integer]] {}
typeLiteral[Array[Int]] shouldEqual new TypeLiteral[Array[Int]] {}
}

it("should handle type parameters that are boxed primative arrays") {
typeLiteral[Array[java.lang.Integer]] shouldEqual new TypeLiteral[Array[java.lang.Integer]] {}
}

it("should handle Primative Arrays") {
typeLiteral[Option[Array[Byte]]] shouldEqual new TypeLiteral[Option[Array[Byte]]] {}
}

it("should create a type literal from a trait") {
Expand All @@ -103,6 +111,17 @@ class TypeLiteralSpec extends FunSpec with Matchers {
it("should handle embedded wildcards with constraints") {
typeLiteral[Option[_ <: Throwable]] shouldEqual new TypeLiteral[Option[_ <: Throwable]] {}
}


it("should handle Unit") {
typeLiteral[Unit] shouldEqual new TypeLiteral[Unit] {}
}

it("Should handle unit as a generic") {
typeLiteral[Function0[Unit]] shouldEqual new TypeLiteral[Function0[Unit]] {}
}

it("Should handle explicit function"){
typeLiteral[Function1[Function0[Unit],String]] shouldEqual new TypeLiteral[(=> Unit) => String] {}
}
}
}

0 comments on commit 5a20e51

Please sign in to comment.