Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala Native 0.4.0 #752

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace class loading with new Reflect api
gabro committed Jan 22, 2021
commit 1ea2c79a4188c5899738ded943205304aa2ed434
27 changes: 18 additions & 9 deletions native/src/main/scala/org/scalacheck/Platform.scala
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ package org.scalacheck

import Test._

import scala.scalanative.testinterface.PreloadedClassLoader
import scala.scalanative.reflect.Reflect

private[scalacheck] object Platform {

@@ -23,14 +23,23 @@ private[scalacheck] object Platform {
workerFun(0)
}

def loadModule(name: String, loader: ClassLoader): AnyRef =
loader.asInstanceOf[PreloadedClassLoader].loadPreloaded(name)
def loadModule(name: String, loader: ClassLoader): AnyRef = {
Reflect
.lookupLoadableModuleClass(name + "$")
.getOrElse(throw new ClassNotFoundException(name + "$"))
.loadModule()
.asInstanceOf[AnyRef]
}

def newInstance(name: String, loader: ClassLoader, paramTypes: Seq[Class[_]])(args: Seq[AnyRef]): AnyRef =
org.scalajs.testinterface.TestUtils.newInstance(name, loader, paramTypes)(args)
def newInstance(name: String, loader: ClassLoader, paramTypes: Seq[Class[_]])(args: Seq[AnyRef]): AnyRef = {
Reflect
.lookupInstantiatableClass(name)
.getOrElse(throw new ClassNotFoundException(name))
.getConstructor(paramTypes: _*)
.getOrElse(throw new NoSuchMethodError(paramTypes.mkString("<init>(", ",", ")")))
.newInstance(args: _*)
.asInstanceOf[AnyRef]
}

// We don't need those annotation in Native, and they have been deprecated.
// We use `String` instead of the definition in Native because `-Xfatal-warnings`
// is set.
type EnableReflectiveInstantiation = String
type EnableReflectiveInstantiation = scala.scalanative.reflect.annotation.EnableReflectiveInstantiation
}