fix(loader): discover stdlib via walk-up + user-share fallbacks (closes #415)#433
Merged
Conversation
#415) Issue #415: `affinescript check file.affine` failed to resolve `use prelude::{Option, Some, None}` outside the repo root because the loader's default config only knew about `./stdlib` and the `AFFINESCRIPT_STDLIB` env var. Idaptik PR #107 hit this directly and had to define a local `enum UndoResult { ... }` as a workaround. Replaces the hard-coded `./stdlib` default with `discover_stdlib`, which tries in order: 1. `$AFFINESCRIPT_STDLIB` — explicit operator override (unchanged) 2. `./stdlib` — current behaviour, in-repo dev (unchanged) 3. **NEW**: walk up from CWD looking for `stdlib/prelude.affine` — catches `affinescript check` runs from any sub-directory of an affinescript repo 4. **NEW**: `<binary_dir>/../share/affinescript/stdlib/` — XDG-style alongside an installed binary (`opam install`, `make install`, etc.) 5. **NEW**: `$HOME/.local/share/affinescript/stdlib/` — user-local install via `cp -r stdlib/ ~/.local/share/affinescript/stdlib/` Falls back to `./stdlib` (preserving the historical `ModuleNotFound` surface) if nothing matches, so misconfigured environments still see a clean error rather than a silent default. Verified locally with three scenarios: in-repo root → `./stdlib` resolves (unchanged) in-repo sub-dir → walk-up finds `stdlib/prelude.affine` (NEW) bare /tmp/ dir → `~/.local/share/.../stdlib/` finds it (NEW, after one-time `cp` install) Does NOT close the literal `use stdlib::Option` parser syntax mentioned in #415 (multi-segment `stdlib::` prefix is still a parse error); that's a grammar change deferred as follow-up. The `Done when` criterion that matters in practice — `affinescript check` succeeds with `use prelude::{Option, Some, None}` from any directory — is met by this PR. Roadmap rows updated to ●: * stdlib roadmap #5 (cross-file `use` resolvability) — `◑` → `●` #6 (Prelude Option reach) and #10 (exhaustive imported-enum match) remain `◑` — they depend on the pattern-compiler change rather than the loader fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🔍 Hypatia Security ScanFindings: 81 issues detected
View findings[
{
"reason": "Action actions/checkout@v6 needs attention",
"type": "unpinned_action",
"file": "publish-jsr.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action denoland/setup-deno@v2 needs attention",
"type": "unpinned_action",
"file": "publish-jsr.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in affine-vscode-publish.yml",
"type": "unknown",
"file": "affine-vscode-publish.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "unknown",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "unknown",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #415. Idaptik PR #107 hit this directly:
use prelude::{Option, Some, None}failed underaffinescript checkwhen invoked from a directory that wasn't the affinescript repo root, because the loader's default config only knew about./stdliband theAFFINESCRIPT_STDLIBenv var. The workaround was a localenum UndoResult { ... }.Replaces the hard-coded
./stdlibdefault withdiscover_stdlib, which tries in order:$AFFINESCRIPT_STDLIB./stdlibstdlib/prelude.affine<binary_dir>/../share/affinescript/stdlib/$HOME/.local/share/affinescript/stdlib/Falls back to
./stdlib(preserves historicalModuleNotFounderror) if nothing matches.Verification (local)
./stdlibresolves (unchanged)/tmp/dir, aftercp -r stdlib ~/.local/share/affinescript/What this PR does NOT do
The literal
use stdlib::Optionparser syntax mentioned in #415's body is a parse error in current grammar (multi-segmentstdlib::prefix not accepted). That's a grammar change deferred as follow-up. The practicalDone whencriterion —affinescript checksucceeds withuse prelude::{Option, Some, None}from any directory — is met by this PR.Roadmap updates
useresolvability)◑→●(follow-up doc PR to flip the row)◑— they depend on the pattern-compiler change rather than the loader fix.🤖 Generated with Claude Code