Skip to content

Reject unexpected tokens instead of skipping them in function bodies #476

Closed

Description

@LunaStev

Problem

The outer function-body parser can silently discard tokens that do not start one of its hand-written statement branches. This allows malformed source to pass wavec check with status 0.

fun main() -> i32 {
    1 ? 2;
    return 0;
}
fun ping() { }
fun main() {
    ping() ping();
}

Both examples succeed on current master plus PR #474. In front/parser/src/parser/functions.rs, the outer-body fallback attempts an expression and then advances past the current token when parsing fails. This differs from nested-block statement parsing and can turn unsupported syntax, missing separators, or typos into a different program.

Silently accepting malformed source is an alpha release blocker.

Scope

  • Remove the token-skipping success path from function bodies.
  • Make every consumed token belong to a successfully parsed declaration, statement, expression, delimiter, or explicit recovery diagnostic.
  • Consolidate the outer function-body and nested-block statement contracts where practical.
  • Define and enforce the separator rule for adjacent expression statements.
  • Add focused negative tests for unsupported infix tokens, missing separators, stray delimiters, and incomplete expressions.
  • Preserve useful multi-error recovery without reporting a successful compilation.

Acceptance criteria

  • Both reproducers fail with stable source diagnostics and a nonzero status.
  • No parser recovery path silently changes program meaning.
  • Existing valid function bodies and nested blocks continue to parse.
  • The compiler never panics while rejecting these inputs.

Related: #346, #406, #474

Activity

  1. added
    bug
    needs testing
    critical
    refactor
    on Sep 5, 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

    bugcriticalneeds testingrefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions