Skip to content

Unexpected use of final in emitted class #8

@joinr

Description

@joinr

Original java:

ThreadLocalRandom tlr = ThreadLocalRandom.current();
long l1 = tlr.nextLong(), l2 = tlr.nextLong();
char[] rt = new char[22];
 rt[21] = tbl[(int)l1 & 0x3f]; l1 = l1 >>> 6;
 rt[20] = tbl[(int)l1 & 0x3f]; l1 = l1 >>> 6;
 rt[19] = tbl[(int)l1 & 0x3f]; l1 = l1 >>> 6;

Corresponding JiSE:

(let [^ThreadLocalRandom tlr (ThreadLocalRandom/current)
      ^long  l1 (.nextLong tlr)
      ^long  l2 (.nextLong tlr)
      ^chars rt (new [char] 22)]
(aset rt 21 (tbl ^int (&  l1 0x3f)))(set! l1 (>>> l1 6))
(aset rt 20 (tbl ^int (&  l1 0x3f)))(set! l1 (>>> l1 6))
(aset rt 19 (tbl ^int (&  l1 0x3f)))(set! l1 (>>> l1 6))
...
)

Inspected with clj-decompiler, using (decompile ...), gives:

final char[] array = new char[22];
final ThreadLocalRandom current = ThreadLocalRandom.current();
final long nextLong = current.nextLong();
final long nextLong2 = current.nextLong();
array[21] = RandM.tbl[(int)(nextLong & 0x3FL)];
final long n = nextLong >>> 6;
array[20] = RandM.tbl[(int)(n & 0x3FL)];
final long n2 = n >>> 6;
array[19] = RandM.tbl[(int)(n2 & 0x3FL)];
...

long variable in let is set to final. Is there a way to allow it to mutate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions