mattunlv / ProcessJ-main-branch-old

ProcessJ Compiler Project
2 stars 4 forks source link

Problem w/ generic arrays #3

Closed cabelshrestha closed 7 years ago

cabelshrestha commented 7 years ago
import std.io;
public proc void main(string args[]) {
  chan<int> p[];
  p = new chan<int>[200];
}

generates:

public synchronized void run() {
  _ld1$p = (PJOne2OneChannel<Integer>[])new Object[200];
  for(int i=0; i < 200; i++) {
    _ld1$p[i] = new PJOne2OneChannel<Integer>();
   };
  terminate();
}

and does this when it runs:

Air:ProcessJ matt$ ./pj test4
Exception in thread "Thread-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LProcessJ.runtime.PJOne2OneChannel;
    at test4$procMain.run(test4.java:15)
    at ProcessJ.runtime.Scheduler.run(Scheduler.java:42)

so I guess that answers my question ;-) There is a problem with generic arrays …..

I think this works: ref: https://www.safaribooksonline.com/library/view/learning-java-4th/9781449372477/ch08s10.html

 public static class procMain extends PJProcess {
        String[] _pd$args;
        PJOne2OneChannel<Integer>[] _ld1$p;

        public procMain(String[] _pd$args) {
            this._pd$args = _pd$args;
        }

        @Override
        public synchronized void run() {
            _ld1$p = new PJOne2OneChannel[200];

            for (int i = 0; i < 200; i++) {
                _ld1$p[i] = new PJOne2OneChannel<Integer>();
            }
            ;
            terminate();
        }
    }

matt

cabelshrestha commented 7 years ago

Fixed.