This page is no longer maintained — Please continue to the home page at www.scala-lang.org

@specialized and protected

2 replies
Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
Hi,
I've just been trying to build scalala with sbt 0.10.1 and 2.9.0-1. The SparseArray class fails to build with:
[info] Compiling 130 Scala sources and 1 Java source to /home/nmrp3/devel/oss/Scalala/target/scala-2.9.0.1/classes... error compiling SparseArray.scala [source-/home/drdozer/devel/oss/Scalala/src/main/scala/scalala/collection/sparse/SparseArray.scala,line-309,offset=10005] [error] {file:/home/drdozer/devel/oss/Scalala/}default-a1cca2/compile: scala.tools.nsc.symtab.Types$TypeError: variable index in class SparseArray cannot be accessed in scalala.collection.sparse.SparseArray[Unit] [error]  Access to protected method index not permitted because[error]  prefix type scalala.collection.sparse.SparseArray[Unit] does not conform to [error]  class SparseArray$mcV$sp in package sparse where the access take place[error] Total time: 46 s, completed 23-Aug-2011 14:33:07
The class is introduced as:
final class SparseArray[@specialized T](val length : Int, protected var index : Array[Int], protected var data : Array[T], protected var used : Int, initialActiveLength : Int) (implicit m : ClassManifest[T], df : DefaultArrayValue[T]) {
The problem method is:
  def set(that : SparseArray[T]): Unit = {    if (this.length != that.length) {       throw new IllegalArgumentException("SparseArrays must be the same length");    }     use(that.index.clone(), that.data.clone(), that.used);  }
It is the access to that.index which is triggering the error. If I remove the @specialized annotation, the class compiles just fine. As a work-around, it compiles if I scope all the protected access modifiers to the current package with [sparse]. So, I'm left wondering if there's something weird going on with specialisation and protected access?
Thanks,
Matthew
--
Dr Matthew PocockVisitor, School of Computing Science, Newcastle Universitymailto: turingatemyhamster [at] gmail [dot] com gchat: turingatemyhamster [at] gmail [dot] commsn: matthew_pocock [at] yahoo [dot] co [dot] uk irc.freenode.net: drdozertel: (0191) 2566550mob: +447535664143
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: @specialized and protected

On Tue, Aug 23, 2011 at 3:45 PM, Matthew Pocock
wrote:
> Hi,
> I've just been trying to build scalala with sbt 0.10.1 and 2.9.0-1. The
> SparseArray class fails to build with:
> [info] Compiling 130 Scala sources and 1 Java source to
> /home/nmrp3/devel/oss/Scalala/target/scala-2.9.0.1/classes...
> error compiling SparseArray.scala
> [source-/home/drdozer/devel/oss/Scalala/src/main/scala/scalala/collection/sparse/SparseArray.scala,line-309,offset=10005]
> [error] {file:/home/drdozer/devel/oss/Scalala/}default-a1cca2/compile:
> scala.tools.nsc.symtab.Types$TypeError: variable index in class SparseArray
> cannot be accessed in scalala.collection.sparse.SparseArray[Unit]
> [error]  Access to protected method index not permitted because
> [error]  prefix type scalala.collection.sparse.SparseArray[Unit] does not
> conform to
> [error]  class SparseArray$mcV$sp in package sparse where the access take
> place
> [error] Total time: 46 s, completed 23-Aug-2011 14:33:07
> The class is introduced as:
> final class SparseArray[@specialized T]
> (val length : Int, protected var index : Array[Int], protected var data :
> Array[T], protected var used : Int, initialActiveLength : Int)
> (implicit m : ClassManifest[T], df : DefaultArrayValue[T]) {
> The problem method is:
>   def set(that : SparseArray[T]): Unit = {
>     if (this.length != that.length) {
>       throw new IllegalArgumentException("SparseArrays must be the same
> length");
>     }
>     use(that.index.clone(), that.data.clone(), that.used);
>   }
> It is the access to that.index which is triggering the error. If I remove
> the @specialized annotation, the class compiles just fine. As a work-around,
> it compiles if I scope all the protected access modifiers to the current
> package with [sparse]. So, I'm left wondering if there's something weird
> going on with specialisation and protected access?

https://issues.scala-lang.org/browse/SI-4541

Search for 'scalala' for additional problems.

-jason

Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
Re: @specialized and protected
Oh, thanks for finding that. Pitty.
Matthew

https://issues.scala-lang.org/browse/SI-4541

Search for 'scalala' for additional problems.

-jason



--
Dr Matthew PocockVisitor, School of Computing Science, Newcastle Universitymailto: turingatemyhamster [at] gmail [dot] com gchat: turingatemyhamster [at] gmail [dot] commsn: matthew_pocock [at] yahoo [dot] co [dot] uk irc.freenode.net: drdozertel: (0191) 2566550mob: +447535664143

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland