Skip to content

fix: wire ensure-or fallback and raise Go coverage#118

Merged
haveyaseen merged 3 commits into
mainfrom
fix/transformer-ensure-or-fallback
Jun 29, 2026
Merged

fix: wire ensure-or fallback and raise Go coverage#118
haveyaseen merged 3 commits into
mainfrom
fix/transformer-ensure-or-fallback

Conversation

@haveyaseen

Copy link
Copy Markdown
Member

Ensure or bad(...) / nominal error payloads are emitted on ensure failure instead of a generic errors.New message. Preserve deferred providers wiring flags across typechecker re-init and skip assignability checks for unknown wiring keys while defer is enabled. Coerce string aliases when Assertion.BaseType is a direct builtin. Add broad unit-test coverage (inline snippets and hooks for goload, safefs, forstpkg, cmd/forst test) so merged Go coverage reaches 79.8%.

fix(transformer): wire ensure-or fallback in Go codegen

transformErrorStatement now lowers custom ensure failure expressions via transformEnsureErrorFallback / ensureFailureErrorExpr. Nominal errors like or NotOk({ msg: "bad" }) emit composite literals, not NotOk(NotOk{...}).

Example:

func f(row Int): Result(String, Error) {
  ensure row is GreaterThan(-1) or bad("too small")
  return "ok"
}

fix(typechecker): preserve deferred wiring state across providers re-init

initProvidersInference no longer drops DeferWiringRootCheck or ForstPackage when CheckTypes re-initializes the providers engine. Unknown wiring keys during deferred merge skip type assignability until post-merge revalidation.

Example:

with { BadKey: &NopLogger {} } {
  use logger: Logger
}

test: expand unit coverage across cmd and internal packages

Add pipeline and direct unit tests for transformer/go (providers, shapes, ensure builtins, cross-package wiring), typechecker inference/providers, generators, goload, safefs, forstpkg, modulecheck, providersgraph, and cmd/forst CLI paths. Introduce test hooks where OS/filesystem branches are hard to reach from unit tests alone.

Ensure `or bad(...)` / nominal error payloads are emitted on ensure failure
instead of a generic errors.New message. Preserve deferred providers wiring
flags across typechecker re-init and skip assignability checks for unknown
wiring keys while defer is enabled. Coerce string aliases when Assertion.BaseType
is a direct builtin. Add broad unit-test coverage (inline snippets and hooks
for goload, safefs, forstpkg, cmd/forst test) so merged Go coverage reaches
79.8%.

fix(transformer): wire ensure-or fallback in Go codegen

transformErrorStatement now lowers custom ensure failure expressions via
transformEnsureErrorFallback / ensureFailureErrorExpr. Nominal errors like
or NotOk({ msg: "bad" }) emit composite literals, not NotOk(NotOk{...}).

Example:
```forst
func f(row Int): Result(String, Error) {
  ensure row is GreaterThan(-1) or bad("too small")
  return "ok"
}
```

fix(typechecker): preserve deferred wiring state across providers re-init

initProvidersInference no longer drops DeferWiringRootCheck or ForstPackage
when CheckTypes re-initializes the providers engine. Unknown wiring keys
during deferred merge skip type assignability until post-merge revalidation.

Example:
```forst
with { BadKey: &NopLogger {} } {
  use logger: Logger
}
```

test: expand unit coverage across cmd and internal packages

Add pipeline and direct unit tests for transformer/go (providers, shapes,
ensure builtins, cross-package wiring), typechecker inference/providers,
generators, goload, safefs, forstpkg, modulecheck, providersgraph, and
cmd/forst CLI paths. Introduce test hooks where OS/filesystem branches are
hard to reach from unit tests alone.
@haveyaseen haveyaseen marked this pull request as ready for review June 29, 2026 00:25
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@haveyaseen, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 4 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 61124b7c-dfb1-4d63-b885-1972e7b190f0

📥 Commits

Reviewing files that changed from the base of the PR and between 97dfe5d and 28f7e7a.

📒 Files selected for processing (78)
  • .cursor/skills/generate-commit-message/SKILL.md
  • forst/cmd/forst/config_test.go
  • forst/cmd/forst/dev_server_http_test.go
  • forst/cmd/forst/generate.go
  • forst/cmd/forst/lsp/diagnostic.go
  • forst/cmd/forst/lsp/providers_lsp_test.go
  • forst/cmd/forst/run_main_test.go
  • forst/cmd/forst/test.go
  • forst/cmd/forst/test_test.go
  • forst/internal/astwalk/walk_test.go
  • forst/internal/compiler/args_test.go
  • forst/internal/forstpkg/forstpkg.go
  • forst/internal/forstpkg/forstpkg_test.go
  • forst/internal/forstpkg/import_paths.go
  • forst/internal/forstpkg/import_paths_test.go
  • forst/internal/forstpkg/parse_recover.go
  • forst/internal/forstpkg/parse_recover_test.go
  • forst/internal/generators/go.go
  • forst/internal/generators/go_test.go
  • forst/internal/goload/load.go
  • forst/internal/goload/load_test.go
  • forst/internal/hasher/hasher_test.go
  • forst/internal/modulecheck/deferred_wiring_unknown_key_test.go
  • forst/internal/modulecheck/find_forst_files_test.go
  • forst/internal/modulecheck/module_providers.go
  • forst/internal/modulecheck/module_revalidate.go
  • forst/internal/modulecheck/module_revalidate_test.go
  • forst/internal/parser/ensure.go
  • forst/internal/parser/parse_constraint_negative_int_test.go
  • forst/internal/providersgraph/edge_test.go
  • forst/internal/providersgraph/graph_test.go
  • forst/internal/providersgraph/propagate_test.go
  • forst/internal/providersgraph/slot_test.go
  • forst/internal/safefs/safefs.go
  • forst/internal/safefs/safefs_test.go
  • forst/internal/testmod/testmod_test.go
  • forst/internal/testrunner/exit_code_test.go
  • forst/internal/testrunner/runner_test.go
  • forst/internal/transformer/go/compound_assign_test.go
  • forst/internal/transformer/go/cross_pkg_module_test.go
  • forst/internal/transformer/go/emit_validation_coverage_test.go
  • forst/internal/transformer/go/emit_validation_examples_test.go
  • forst/internal/transformer/go/ensure_builtins_test.go
  • forst/internal/transformer/go/ensure_test.go
  • forst/internal/transformer/go/expression_string_alias.go
  • forst/internal/transformer/go/pipeline_emit_ensure_test.go
  • forst/internal/transformer/go/pipeline_integration_test.go
  • forst/internal/transformer/go/statement_ensure.go
  • forst/internal/transformer/go/statement_ensure_fallback_test.go
  • forst/internal/transformer/go/statement_helpers.go
  • forst/internal/transformer/go/statement_return_zero_helpers_test.go
  • forst/internal/transformer/go/transformer_pipeline_coverage_test.go
  • forst/internal/transformer/go/transformer_shape_wiring_coverage_test.go
  • forst/internal/transformer/go/transformer_unit_coverage_test.go
  • forst/internal/transformer/go/typedef_expr_branch_test.go
  • forst/internal/typechecker/alias_return_test.go
  • forst/internal/typechecker/channel_type_test.go
  • forst/internal/typechecker/check_types_snippets_test.go
  • forst/internal/typechecker/example_ft_bundle_test.go
  • forst/internal/typechecker/infer_assertion_test.go
  • forst/internal/typechecker/infer_assignment_test.go
  • forst/internal/typechecker/infer_function_test.go
  • forst/internal/typechecker/infer_nominal_error_test.go
  • forst/internal/typechecker/lookup_field_assertion_test.go
  • forst/internal/typechecker/lookup_field_path_resolve_alias_test.go
  • forst/internal/typechecker/lookup_function_test.go
  • forst/internal/typechecker/narrowing_display_test.go
  • forst/internal/typechecker/param_shape_test.go
  • forst/internal/typechecker/providers_engine.go
  • forst/internal/typechecker/providers_engine_test.go
  • forst/internal/typechecker/providers_finish_test.go
  • forst/internal/typechecker/providers_obligation_chain_test.go
  • forst/internal/typechecker/providers_scope.go
  • forst/internal/typechecker/result_err_branch_return_test.go
  • forst/internal/typechecker/unify_is_test.go
  • forst/internal/typechecker/unify_operators_test.go
  • forst/internal/typechecker/unify_shape_test.go
  • forst/internal/typechecker/utils_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/transformer-ensure-or-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Reject lowercase identifiers after ensure-or at parse time so error
handlers follow the same exported-name convention as constraints and
nominal errors. Update parser and transformer tests accordingly.

Also update the generate-commit-message skill to forbid code examples in
commit message output.

BREAKING CHANGE: lowercase ensure-or handlers are now parse errors;
rename handlers to start with an uppercase letter.
Replace unchecked defer os.Chdir and Close calls with t.Cleanup and
explicit error discard, rename unused test parameters to _, switch
WriteString(fmt.Sprintf(...)) to fmt.Fprintf, remove dead go:fix inline
helpers, and inline a ptrTypeIdent call so errcheck, revive, staticcheck,
govet, and unused linters pass.

fix(parser): allow lowercase ensure or error handlers

Drop the rule requiring ensure or handlers to start with an uppercase
letter. Lowercase variable passthrough (or err) and function calls
(or invalidMove(...)) are valid and used in examples; the restriction
broke ensure.ft, tictactoe, and downstream module typechecking.
@haveyaseen haveyaseen merged commit 228ff54 into main Jun 29, 2026
3 of 4 checks passed
@haveyaseen haveyaseen deleted the fix/transformer-ensure-or-fallback branch June 29, 2026 00:39
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant