Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Metapath functions with multiple parameters drops parameters #320

Closed
aj-stein-gsa opened this issue Dec 31, 2024 · 0 comments · Fixed by #321
Closed

Parsing Metapath functions with multiple parameters drops parameters #320

aj-stein-gsa opened this issue Dec 31, 2024 · 0 comments · Fixed by #321
Assignees
Labels
bug Something isn't working
Milestone

Comments

@aj-stein-gsa
Copy link
Contributor

Describe the bug

When using recent versions of metaschema-java, when using functions with multiple parameters, the parser builds a concrete syntax tree and drops parameters and by index reuses the previous arguments to overwrite the value. This parsing error leads to incorrect results from function calls.

Who is the bug affecting

Developers using Metaschema-enabled software and Metapath-based constraints for model-based documents with Metapath functions that have more than one parameter.

How do we replicate this issue

  1. Use the metaschema-cli to evaluate the function below or run the following unit test.
metaschema-cli metapath eval --expression "let $boom := function ($argument1, $argument2) { $argument2 } return $boom('a', 'b')"
/*
 * SPDX-FileCopyrightText: none
 * SPDX-License-Identifier: CC0-1.0
 */

package gov.nist.secauto.metaschema.core.metapath.cst;

import static org.junit.jupiter.api.Assertions.assertEquals;

import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.ExpressionTestBase;
import gov.nist.secauto.metaschema.core.metapath.IMetapathExpression;
import gov.nist.secauto.metaschema.core.metapath.IMetapathExpression.ResultType;
import gov.nist.secauto.metaschema.core.metapath.StaticContext;
import gov.nist.secauto.metaschema.core.qname.IEnhancedQName;

import org.junit.jupiter.api.Test;


class FunctionParameterTest
    extends ExpressionTestBase {

  @Test
  void testMultipleParameters() {
    StaticContext staticContext = StaticContext.builder().build();
    DynamicContext dynamicContext = new DynamicContext(staticContext);
    String metapath = "function ($argument1 as meta:string, $argument2 as meta:string) as meta:string { $argument2 }";
    dynamicContext.bindVariableValue(IEnhancedQName.of("boom"), 
    		IMetapathExpression.compile(metapath, staticContext).evaluate(null, dynamicContext));    
    String result = IMetapathExpression.compile("$boom('a', 'b')", staticContext).evaluateAs(null, ResultType.STRING , dynamicContext);
    assertEquals(result, "b");
    
  }
}

Expected behavior (i.e. solution)

The function successfully evaluates to b (an item of type meta:string.

Other comments

No response

@aj-stein-gsa aj-stein-gsa added the bug Something isn't working label Dec 31, 2024
@aj-stein-gsa aj-stein-gsa self-assigned this Dec 31, 2024
aj-stein-gsa added a commit to aj-stein-gsa/metaschema-java that referenced this issue Dec 31, 2024
aj-stein-gsa added a commit to aj-stein-gsa/metaschema-java that referenced this issue Dec 31, 2024
aj-stein-gsa added a commit to aj-stein-gsa/metaschema-java that referenced this issue Dec 31, 2024
@aj-stein-gsa aj-stein-gsa moved this from To Triage to Backlog in Spec and Tooling Work Board Dec 31, 2024
@aj-stein-gsa aj-stein-gsa moved this from Backlog to Ready in Spec and Tooling Work Board Dec 31, 2024
@aj-stein-gsa aj-stein-gsa moved this from Ready to In progress in Spec and Tooling Work Board Dec 31, 2024
@aj-stein-gsa aj-stein-gsa moved this from In progress to In review in Spec and Tooling Work Board Dec 31, 2024
david-waltermire pushed a commit to aj-stein-gsa/metaschema-java that referenced this issue Jan 2, 2025
@david-waltermire david-waltermire added this to the v2.2.0 milestone Jan 2, 2025
@github-project-automation github-project-automation bot moved this from In review to Done in Spec and Tooling Work Board Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
2 participants