Can no longer use anonymous classes after upgrading to version 1.0.0 - scala.js

I have just tried upgrading my project from version 0.6.x to the latest version 1.0.0-M8 and am now getting a string of compilation errors anywhere I had declared an anonymous class.
So for example if I did:
def myFunc(x: Int) = new { ... }
val x = new SomeAbstractClass(p1, p2) { ... }
I get the compilation errors:
Error: type WasPublicBeforeTyper is not a member of package
scala.scalajs.js.annotation def myFunc(node: Node) = new {
Error: type WasPublicBeforeTyper is not a member of package
scala.scalajs.js.annotation
form = new SomeAbstractClass(p1, p2) {

Related

sbt could not find implicit value for parameter valName

I'm using sbt to build some of the riscv boom from the source code, but the sbt complains that it "could not find implicit value for parameter valName: : freechips.rocketchip.diplomacy.ValName". The detailed error message are as below:
[error] F:\hiMCU\my_proj\src\main\scala\freechips\rocketchip\tile\BaseTile.scala:170:42: could not find implicit value for parameter valName: freechips.rocketchip.diplomacy.ValName
[error] Error occurred in an application involving default arguments.
[error] protected val tlMasterXbar = LazyModule(new TLXbar)
The code where sbt complains is as below:
abstract class BaseTile private (val crossing: ClockCrossingType, q: Parameters)
extends LazyModule()(q)
with CrossesToOnlyOneClockDomain
with HasNonDiplomaticTileParameters
{
// Public constructor alters Parameters to supply some legacy compatibility keys
def this(tileParams: TileParams, crossing: ClockCrossingType, lookup: LookupByHartIdImpl, p: Parameters) = {
this(crossing, p.alterMap(Map(
TileKey -> tileParams,
TileVisibilityNodeKey -> TLEphemeralNode()(ValName("tile_master")),
LookupByHartId -> lookup
)))
}
def module: BaseTileModuleImp[BaseTile]
def masterNode: TLOutwardNode
def slaveNode: TLInwardNode
def intInwardNode: IntInwardNode // Interrupts to the core from external devices
def intOutwardNode: IntOutwardNode // Interrupts from tile-internal devices (e.g. BEU)
def haltNode: IntOutwardNode // Unrecoverable error has occurred; suggest reset
def ceaseNode: IntOutwardNode // Tile has ceased to retire instructions
def wfiNode: IntOutwardNode // Tile is waiting for an interrupt
protected val tlOtherMastersNode = TLIdentityNode()
protected val tlSlaveXbar = LazyModule(new TLXbar)
protected val tlMasterXbar = LazyModule(new TLXbar)
protected val intXbar = LazyModule(new IntXbar)
....
}
The LazyModule object code is as below:
object LazyModule
{
protected[diplomacy] var scope: Option[LazyModule] = None
private var index = 0
def apply[T <: LazyModule](bc: T)(implicit valName: ValName, sourceInfo: SourceInfo): T = {
// Make sure the user put LazyModule around modules in the correct order
// If this require fails, probably some grandchild was missing a LazyModule
// ... or you applied LazyModule twice
require (scope.isDefined, s"LazyModule() applied to ${bc.name} twice ${sourceLine(sourceInfo)}")
require (scope.get eq bc, s"LazyModule() applied to ${bc.name} before ${scope.get.name} ${sourceLine(sourceInfo)}")
scope = bc.parent
bc.info = sourceInfo
if (!bc.suggestedNameVar.isDefined) bc.suggestName(valName.name)
bc
}
}
I think the sbt should find some val of type freechips.rocketchip.diplomacy.ValName, but it didn't find such kind of val.
You need to have an object of type ValName in the scope where your LazyModules are instantiated:
implicit val valName = ValName("MyXbars")
For more details on Scala's implicit please see https://docs.scala-lang.org/tutorials/tour/implicit-parameters.html.html
You generally shouldn't need to manually create a ValName, the Scala compiler can materialize them automatically based on the name of the val you're assigning the LazyModule to. You didn't include your imports in your example, but can you try importing ValName?
import freechips.rocketchip.diplomacy.ValName
In most of rocket-chip code, this is imported via wildcard importing everything in the diplomacy package
import freechips.rocketchip.diplomacy._

Side-effecting nullary methods are discouraged: suggest defining as ... for IntelliJ

I executed this code block in a IntelliJ worksheet (Community Edition EAP 15#143.379.11 with Scala plugin 1.9.4 on JDK 1.8.0_66) ,
class Plant
class Fruit extends Plant
class Apple extends Fruit
class Box[T <: Fruit](var item: T) {
def get: T = item
def replace(item: T): Unit = this.item = item
}
val appleBox = new Box(new Apple)
println(appleBox.get) // error
and IntelliJ reported this error during worksheet compilation and stopped,
Error:(22, -59) side-effecting nullary methods are discouraged: suggest defining as `def get$$instance$$res0()` instead
println(appleBox.get);//
^
How do I disable this error or change it to warning and let me continue? I am using IntelliJ . Thanks
To avoid an error just remove println, Scala Worksheet will print the object for you.
val appleBox = new Box(new Apple)
appleBox.get
appleBox: Box[Apple] = Box#4109bbc4
res0: Apple = Apple#6e2e3a8b
PS: I do not get the error you are reporting in the latest EAP Scala Plugin (1.9.272)

Scala in depth - Existential types

I am currently reading Scala in depth and I struggle with a point about existential types.
Using those sources : https://github.com/jsuereth/scala-in-depth-source/blob/master/chapter6/existential-types/existential.scala
with openjdk 7 and scala 2.10.3
The following instructions gives me a error :
val x = new VariableStore[Int](12)
val d = new Dependencies {}
val t = x.observe(println)
d.addHandle(t)
<console>:14: error: method addHandle in trait Dependencies cannot be accessed in types.Dependencies
Access to protected method addHandle not permitted because
enclosing object $iw is not a subclass of
trait Dependencies in package types where target is defined
d.addHandle(t)
^
And I can't find out why and how I arrive to this error.
Edit 1 :
I added the following code from Kihyo's answer :
class MyDependencies extends Dependencies {
override def addHandle(handle: Ref) = super.addHandle(handle)
}
val x = new VariableStore[Int](12)
val d = new MyDependencies
val t = x.observe(println)
d.addHandle(t) //compiles
It make addHandle public instead of protected.
Now I have the following error message :
type mismatch; found : x.Handle (which expands to) x.HandleClass required: d.Ref (which
expands to) x.Handle forSome { val x: sid.types.obs.Observable }
HandleClass is a Handle and Ref is a Handle of any Observer (if I get it right) so the value t should be accepted as a correct type for the exception.
In the trait Dependencies, addHandle is defined like that:
protected def addHandle(handle : Ref) : Unit
protected means, only subclasses can access this method and thats why you get the error. (which basically tells you exactly that)
Your code could work when you create a subclass that makes addHandle public:
class MyDependencies extends Dependencies {
override def addHandle(handle: Ref) = super.addHandle(handle)
}
val x = new VariableStore[Int](12)
val d = new MyDependencies
val t = x.observe(println)
d.addHandle(t) //compiles
But I have no idea about that example and what you want to do with it.
#Edit1:
I get the same error as you, but I can't explain why. It worked for me when I extend App instead of having a main-method:
object TestObs extends App {
val x = new VariableStore[Int](12)
val d = new MyDependencies
val t = x.observe(println)
d.addHandle(t)
}
Maybe someone else has some insight on this.

Scala path dependent return type from parameter

In the following code using 2.10.0M3 in Eclipse plugin 2.1.0 for 2.10M3. I'm using the default setting which is targeting JVM 1.5
class GeomBase[T <: DTypes] {
abstract class NewObjs {
def newHex(gridR: GridBase, coodI: Cood): gridR.HexRT
}
class GridBase {
selfGrid =>
type HexRT = HexG with T#HexTr
def uniformRect (init: NewObjs) {
val hexCood = Cood(2 ,2)
val hex: HexRT = init.newHex(selfGrid, hexCood)// won't compile
}
}
}
Error message:
Description Resource Path Location Type type mismatch;
found: GeomBase.this.GridBase#HexG with T#HexTr
required: GridBase.this.HexRT (which expands to) GridBase.this.HexG with T#HexTr GeomBase.scala
Why does the compiler think the method returns the type projection GridBase#HexG when it should be this specific instance of GridBase?
Edit transferred to a simpler code class in responce to comments now getting a different error message.
package rStrat
class TestClass {
abstract class NewObjs {
def newHex(gridR: GridBase): gridR.HexG
}
class GridBase {
selfGrid =>
def uniformRect (init: NewObjs) {
val hex: HexG = init.newHex(this) //error here
}
class HexG {
val test12 = 5
}
}
}
.
Error line 11:Description Resource Path Location Type
type mismatch; found : gridR.HexG required: GridBase.this.HexG
possible cause: missing arguments for method or constructor TestClass.scala /SStrat/src/rStrat line 11 Scala Problem
Update I've switched to 2.10.0M4 and updated the plug-in to the M4 version on a fresh version of Eclipse and switched to JVM 1.6 (and 1.7) but the problems are unchanged.
logged as SI-5958 - substitute this in dependent method type
This now works as of 2.10.0M7. The bug has been fixed.
val hex: HexRT = init.newHex(selfGrid, hexCood) //now compiles and runs correctly

cannot find class manifest for element type T

Was trying to compile some code from this SO question and run into this error message cannot find class manifest for element type T. Here is another snippet that shows the behavior:
scala> def f[T](a:T, b:T):Array[T] = { new Array[T](2) }
<console>:4: error: cannot find class manifest for element type T
def f[T](a:T, b:T):Array[T] = { new Array[T](2) }
I can see that new collection.mutable.GenericArray[T](2) fixes the issue. Apparently providing a manifest is the other option... But what does "providing a manifest mean"?
To provide type information you can use a context bound
def f[T : Manifest](a:T, b:T):Array[T] = { new Array[T](2) }
or the manifest as an implicit argument:
def f[T](a:T, b:T)(implicit manifest : Manifest[T]) : Array[T] = { new Array[T](2) }
The former is syntactic sugar for the later. The manifest is needed because the type information about T is missing due to generic type errasure of the JVM.