CraftTweaker

CraftTweaker

151M Downloads

Can't Deep Copy Arrays

Opened this issue ยท 1 comments

commented

Issue description

The following code:

  var x = [5] as int[];
  var y = x.copy() as int[];
  x[0] = 3;
  print(y[0]);

should do a deep copy of the array and print 5 to the console, but instead it prints 3. This means the copy() method basically does nothing on arrays.

Also, the following line:

[5].copy(1);

produces an error on reloading:

[11:09:14.051][DONE][CLIENT][ERROR] Bad type on operand stack
Exception Details:
  Location:
    scripts/test.run()V @12: invokestatic
  Reason:
    Type '[I' (current frame, stack[0]) is not assignable to '[Ljava/lang/Object;'
  Current Frame:
    bci: @12
    flags: { }
    locals: { }
    stack: { '[I', integer }
  Bytecode:
    0x0000000: 1208 bc0a 5912 0912 0a4f 1208 b800 1057
    0x0000010: b1                                     

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    scripts/test.run()V @12: invokestatic
  Reason:
    Type '[I' (current frame, stack[0]) is not assignable to '[Ljava/lang/Object;'
  Current Frame:
    bci: @12
    flags: { }
    locals: { }
    stack: { '[I', integer }
  Bytecode:
    0x0000000: 1208 bc0a 5912 0912 0a4f 1208 b800 1057
    0x0000010: b1                                     

	at Scripts.run(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit.run(JavaBytecodeRunUnit.java:127)
	at org.openzen.zencode.java.ScriptingEngine.run(ScriptingEngine.java:165)
	at com.blamejared.crafttweaker.api.zencode.impl.loaders.ScriptRun.readAndExecuteScripts(ScriptRun.java:124)
	at com.blamejared.crafttweaker.api.zencode.impl.loaders.ScriptRun.run(ScriptRun.java:94)
	at com.blamejared.crafttweaker.api.CraftTweakerAPI.loadScripts(CraftTweakerAPI.java:134)
	at com.blamejared.crafttweaker.api.CraftTweakerAPI.loadScriptsFromRecipeManager(CraftTweakerAPI.java:165)
	at com.blamejared.crafttweaker.CraftTweaker.getRecipes(CraftTweaker.java:206)
	at net.minecraftforge.eventbus.ASMEventHandler_18_CraftTweaker_getRecipes_RecipesUpdatedEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
	at net.minecraftforge.eventbus.EventBus$$Lambda$2546/941240062.invoke(Unknown Source)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
	at net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(ForgeHooksClient.java:711)
	at net.minecraft.client.network.play.ClientPlayNetHandler.func_199525_a(ClientPlayNetHandler.java:1314)
	at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:27)
	at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:15)
	at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21)
	at net.minecraft.network.PacketThreadUtil$$Lambda$5968/1751958098.run(Unknown Source)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144)
	at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103)
	at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:947)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607)
	at net.minecraft.client.main.Main.main(Main.java:184)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51)
	at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$427/1031586763.call(Unknown Source)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)

as does any time the copy(newSize as usize) method is used on an array.

Sorry if this should be in the ZenScript issue tracker instead.

Steps to reproduce

No response

Script used

https://gist.github.com/zermelo-fraenkel-choice/491dd615659deeaa9d2730fb86adc67b#file-test-zs

The crafttweaker.log file

https://gist.github.com/zermelo-fraenkel-choice/491dd615659deeaa9d2730fb86adc67b#file-crafttweaker-log

Minecraft version

1.16

Forge version

36.2.2

CraftTweaker version

7.1.0.389

Other relevant information

Both scripts are in the same gist. but I only linked to the first one.

The latest.log file

https://gist.github.com/zermelo-fraenkel-choice/491dd615659deeaa9d2730fb86adc67b#file-latest-log

commented

Thanks for the report!

It's going to be tracked here:
ZenCodeLang/ZenCode#42, I'll close this issue when that issue is resolved.