fix(template-engine): validate CallShared/CallScript parameters object by name (#150)
The semantic validator treated each comma-separated argument after the
script name as a positional parameter and required the count to equal the
declared ParameterDefinitions. The runtime has no positional form: both
calls take ONE parameters object that ScriptArgs.Normalize turns into a
name -> value dictionary, so every Scripts.CallShared("X", new { ... })
was rejected unless exactly one parameter was declared, blocking deploy.
Call sites are now found with a Roslyn script-mode syntax parse (named
arguments and a trailing CancellationToken handled; calls in comments or
strings ignored). The parameters argument is classified as:
- anonymous object: validated by name (ordinal) - missing required
parameter = error, undeclared member = warning, clear literal type
mismatch per member = error (same conservative inference as before);
- any other expression (variable, dictionary, call, null): not checked;
- absent: error only if the target declares required parameters.
Required-ness comes from the shared InboundApiSchema parser (JSON Schema
'required' list; legacy array entries required unless required:false).
Positional-argument tests replaced by by-name CallShared/CallScript tests;
Component-TemplateEngine.md updated.
This commit is contained in:
@@ -310,7 +310,7 @@ Before a deployment is sent to a site, the Template Engine performs comprehensiv
|
||||
Beyond compilation, the Template Engine performs static semantic checks:
|
||||
|
||||
- **Script call targets**: `Instance.CallScript()` and `Scripts.CallShared()` targets must reference scripts that exist in the flattened configuration or shared script library.
|
||||
- **Argument compatibility**: Parameter count and data types at call sites must match the target script's parameter definitions.
|
||||
- **Argument compatibility** (`ValidationCategory.ParameterMismatch`): `CallScript`/`CallShared` take one parameters object (anonymous object or dictionary, normalized by `ScriptArgs` into a name → value dictionary — there is no positional form), so call sites are checked by **name** (ScadaBridge#150). When the parameters argument is an anonymous object (`new { A = 1, B = x }`), every required declared parameter must be present (error), a member the target does not declare is a **warning**, and a member whose literal value clearly mismatches the declared type is an error (non-literal values are never type-flagged). Any other parameters expression (a variable, dictionary, method call, `null`) is not checked. A call with no parameters argument against a target that declares required parameters is an error. A trailing `CancellationToken` argument is ignored. Call sites are located with a Roslyn syntax parse, so calls inside comments or strings are not validated.
|
||||
- **Return type compatibility**: If a script call's return value is used, the return type definition must match the caller's expectations.
|
||||
- **Trigger operand types**: Alarm triggers and script conditional triggers must reference attributes with compatible data types (e.g., Range Violation requires numeric attributes).
|
||||
- **Native alarm sources** (`ValidationCategory.NativeAlarmSourceInvalid`): `SemanticValidator.Validate` flags a `ResolvedNativeAlarmSource` when its `SourceReference` is empty, its `ConnectionName` is empty, or — when the caller supplies the alarm-capable connection set — its connection is unknown or not alarm-capable (protocol ∉ {`OpcUa`, `MxGateway`}). The alarm-capable connection set is an **optional, additive third parameter** to `Validate`; the empty-field checks always run, and the connection-binding check runs only when the set is provided.
|
||||
|
||||
Reference in New Issue
Block a user