diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-04-22 07:11:13 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-04-22 08:00:39 +0000 |
commit | bd6c9221ccd1e83c7e0d9e58d018b4aae6829b46 (patch) | |
tree | 9326fe48cf5348a1327fe7fa891c9958e0acbd61 /config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java | |
parent | 54cf8a76701363e83da3e3f39dc4ae38597d586a (diff) |
resolve bindings via parent context
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java index fc7362a43e1..e8ee5e9ed57 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java @@ -129,6 +129,19 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement return resolvedType; } + MapEvaluationTypeContext getParent(String forArgument, String boundTo) { + return parent.orElseThrow( + () -> new IllegalArgumentException("argument "+forArgument+" is bound to "+boundTo+" but there is no parent context")); + } + + String resolveBinding(String argument) { + String bound = getBinding(argument); + if (bound == null) { + return argument; + } + return getParent(argument, bound).resolveBinding(bound); + } + private TensorType resolveType(Reference reference) { if (currentResolutionCallStack.contains(reference)) throw new IllegalArgumentException("Invocation loop: " + @@ -142,8 +155,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement // This is not pretty, but changing to bind expressions rather // than their string values requires deeper changes var expr = new RankingExpression(binding.get()); - var type = expr.type(parent.orElseThrow( - () -> new IllegalArgumentException("when a binding is present we must have a parent context"))); + var type = expr.type(getParent(reference.name(), binding.get())); return type; } catch (ParseException e) { throw new IllegalArgumentException(e); @@ -157,8 +169,8 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement if (FeatureNames.isSimpleFeature(reference)) { // The argument may be a local identifier bound to the actual value String argument = reference.simpleArgument().get(); - String argumentBinding = getBinding(argument); - reference = Reference.simple(reference.name(), argumentBinding != null ? argumentBinding : argument); + String argumentBinding = resolveBinding(argument); + reference = Reference.simple(reference.name(), argumentBinding); return featureTypes.get(reference); } |