CommandHelper

CommandHelper

46.5k Downloads

Executing closure in short form from an array

Anatoliy057 opened this issue ยท 3 comments

commented

If we execute closures in short form from an array, we get:

@a = array(closure(){return(@arguments)})
@b = @a[0](1, 2)
console(@b)
console(is_closure(@b))
console(@a[0](1, 2))
console(is_string(@a[0](1, 2)))

return(@arguments)
true
return(@arguments) 1 2
true

Without arguments:

@a = associative_array(closure(){return(@arguments)})
console(@a[0]())

Uh oh! You've found an error in Core.
This happened while running your code, so you may be able to find a workaround, (though since this is an Error, maybe not) but is ultimately an issue in Core.
The following code caused the error:
__autoconcat__()
on or around C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\main.ms:2.
Please report this to the developers, and be sure to include the version numbers:
Server version: 1.13.2-R0.1-SNAPSHOT;
CommandHelper version: 3.3.4;
Loaded extensions and versions:
CHCadabra (0.0.2)
Core (3.3.4)
CHFiles (2.2.6)
Here's the stacktrace:
java.lang.Error: Should not have gotten here, __autoconcat__ was not removed before runtime.
        at com.laytonsmith.core.functions.Compiler$__autoconcat__.exec(Compiler.java:140)
        at com.laytonsmith.core.Script.eval(Script.java:409)
        at com.laytonsmith.core.Script.eval(Script.java:375)
        at com.laytonsmith.core.Script.eval(Script.java:375)
        at com.laytonsmith.core.Script.eval(Script.java:375)
        at com.laytonsmith.core.MethodScriptCompiler.execute(MethodScriptCompiler.java:2808)
        at com.laytonsmith.core.MethodScriptCompiler.execute(MethodScriptCompiler.java:2766)
        at com.laytonsmith.core.AliasCore$LocalPackage.compileMS(AliasCore.java:746)
        at com.laytonsmith.core.AliasCore.reload(AliasCore.java:384)
        at com.laytonsmith.commandhelper.CommandHelperPlugin.onCommand(CommandHelperPlugin.java:575)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:704)
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:689)
        at net.minecraft.server.v1_13_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:459)
        at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:418)
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831)
        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729)
        at java.lang.Thread.run(Unknown Source)

Same for associated array.

commented

Fixed here: ab21e60

commented

Because there's a stacktrace, this is a bug, but executing closures with () isn't yet supported. See execute().

commented

For clarity, @var() is supported, but @var[0]() is not yet supported.