Skip to content

Tests: await in generator coverage (§14) #482

Closed

Description

@ehartford

Summary

Add regression coverage for .await inside generators. The compiler already rejects it, but the requirement is currently verified manually rather than by a dedicated compile-error test.

Spec

docs/with-specification.md:7310-7338 distinguishes generators from async functions. docs/with-specification.md:7320 says generators suspend at yield while async functions suspend at scheduler points. docs/with-specification.md:7329 says a gen fn cannot use .await. docs/requirements.md:7031-7048 records the §14.20 generator/async split, including requirement 14.20.1.14.

Current state

src/SemaCheck.w:3170-3206 checks NK_AWAIT. When current_fn_is_gen is set, src/SemaCheck.w:3174-3175 emits await is not allowed in generator function. Generator yield checking is separate at src/SemaCheck.w:3240-3260.

test/spec/spec_ss13_4_generators.w covers positive generator behavior. No dedicated test/compile_errors/err_generator_await.w-style test exists, and out/req-campaign/g07.tsv records this requirement as manually verified only.

Implementation plan

  1. Add a minimal compile-error test with a gen fn whose body attempts to .await an async result.
  2. Use //! expect-check-fail: await is not allowed in generator function so the test locks the existing diagnostic.
  3. Keep the fixture minimal enough that the only expected failure is the generator/await rule, not missing runtime or scheduler setup.
  4. If the async fixture needs helper definitions, reuse the smallest existing async test pattern instead of introducing new async semantics.

Test plan

Run the new compile-error test directly, then run with build :test. Confirm the test fails if the current_fn_is_gen guard in check_await is removed.

Acceptance criteria

  • A compile-error test covers .await inside gen fn.
  • The expected diagnostic is the existing await is not allowed in generator function message.
  • Positive generator tests and positive async-await tests continue to pass.

Dependencies

Overlaps #504, which tracks the same restriction from the §13.4 requirements side. One shared test can satisfy both if named and documented clearly.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 14.20.1.14.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — await inside a generator (gen fn) rejected, pinned by err_generator_await (13f4f88, 'await is not allowed in generator function'). Duplicate of the negative added for #504. §14/§13.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions