Skip to content

Commit b071a43

Browse files
authored
Merge pull request #22 from bluelhf/fix/function-property-stack-order
Fix stack ordering problems in function property
2 parents 8445d2d + f9ae046 commit b071a43

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/byteskript/skript/lang/syntax/function/ExprFunctionProperty.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public void preCompile(Context context, Pattern.Match match) throws Throwable {
106106
for (final ElementTree tree : context.getCompileCurrent().nested()) {
107107
tree.takeAtomic = true;
108108
}
109-
final String name = ((FunctionDetails) match.meta()).name();
110-
context.getMethod().writeCode(WriteInstruction.loadConstant(name)); // ldc name
111109
final ElementTree[] nested = context.getCompileCurrent().nested();
112110
if (nested.length < 2) return;
113111
final ElementTree tree = nested[nested.length - 1]; // swap object order before array pack
@@ -138,6 +136,11 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
138136
target.writeCode(WriteInstruction.returnObject());
139137
}
140138
method.writeCode(WriteInstruction.invokeStatic(builder.getType(), erasure)); // pack array
139+
final String name = ((FunctionDetails) match.meta()).name();
140+
context.getMethod().writeCode(WriteInstruction.loadConstant(name));
141+
// shuffle stack from (source, params, name) -> (name, source, params)
142+
method.writeCode(WriteInstruction.duplicateDrop3());
143+
method.writeCode(WriteInstruction.pop());
141144
this.writeCall(method, findMethod(Metafactory.class, "callFunction", String.class, Object.class, Object[].class), context);
142145
}
143146

0 commit comments

Comments
 (0)