From ef5fba0f057b8106ad199f530e9b1b6d95c0a585 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Thu, 27 Oct 2011 16:53:44 +0200 Subject: [PATCH] Improved accuracy of Function.getPosition() after optimization. --- .../com/sk89q/worldedit/expression/runtime/Function.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/Function.java b/src/main/java/com/sk89q/worldedit/expression/runtime/Function.java index 41c5584bb..362498766 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Function.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Function.java @@ -76,19 +76,24 @@ public class Function extends Invokable { public Invokable optimize() throws EvaluationException { final Invokable[] optimizedArgs = new Invokable[args.length]; boolean optimizable = !method.isAnnotationPresent(Dynamic.class); + int position = getPosition(); for (int i = 0; i < args.length; ++i) { final Invokable optimized = optimizedArgs[i] = args[i].optimize(); if (!(optimized instanceof Constant)) { optimizable = false; } + + if (optimized.getPosition() < position) { + position = optimized.getPosition(); + } } if (optimizable) { - return new Constant(getPosition(), invoke()); + return new Constant(position, invoke()); } else { - return new Function(getPosition(), method, optimizedArgs); + return new Function(position, method, optimizedArgs); } } }