Skip to content

engine: SMTH3(5) and other short stdlib calls compile without error #1031

Open

Description

@bpowers

Calling SMTH1, SMTH3, DELAY1, DELAY3, TREND or NPV with too few arguments compiles and simulates with no error.
It should be rejected, the way too many arguments already are.

Example

<aux name="s3"><eqn>SMTH3(5)</eqn></aux>

simlin simulate gives s3 = 5 at every step, with the delay time silently set to the stdlib model's default of 1 and no warning.
SMTH3(5, 3, 7, 9) is correctly rejected: "smth3 takes at most 3 argument(s), but 4 were given".

Why it matters

A missing delay time is an easy mistake, and today it silently produces a model with a different time constant.
Constructed case; not reported from a real model.

Fix

Give each stdlib function a minimum argument count next to its port list: 2 for the smooth/delay/trend family (input, delay time; initial value optional), 2 for NPV (stream, discount rate).
Reject fewer with BadBuiltinArgs over the call.
Derive the test rows from stdlib_args so a function added later cannot skip the check.

Pointers

  • src/simlin-engine/src/builtins_visitor.rs: expand_module_function (the existing at-most check)
  • src/simlin-engine/src/module_functions.rs: stdlib_args, ModuleFunctionDescriptor

Activity

  1. added
    bug
    engine
    on Aug 26, 2026
  2. bpowers commented on Sep 2, 2026

    @bpowers
    OwnerAuthor

    Status (compiler-unification-v2, Phase 7.3): the over-arity half is now refused -- builtins_visitor::expand_module_function returns BadBuiltinArgs ("smth1 takes at most 3 argument(s), but 4 were given") before any argument is hoisted, pinned by db::implicit_module_tests::a_call_with_more_arguments_than_ports_is_refused_before_any_hoist. Under-arity (SMTH1(k) compiling with the template's default averaging time) is still accepted and remains this issue's scope; the fix needs a per-port required/optional fact on module_functions::stdlib_args.

  3. changed the title [-]engine: stdlib module functions accept any argument count -- SMTH3(5) simulates silently[/-] [+]engine: SMTH3(5) and other short stdlib calls compile without error[/+] on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions