Skip to content

fix(typecheck): instantiate constructor schemes per use-site in patterns (#128)#187

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/128-ctor-per-use-instantiation
May 18, 2026
Merged

fix(typecheck): instantiate constructor schemes per use-site in patterns (#128)#187
hyperpolymath merged 1 commit into
mainfrom
fix/128-ctor-per-use-instantiation

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

STAGE A (#128/#135). Soundness fix.

check_pattern's PatCon read the monomorphic constructor_env entry and wrapped it as a 0-tyvar scheme, so every occurrence of a constructor shared one set of type variables. Two Ok(_) patterns in a single match (e.g. result.affine's apply tuple match) forced both payloads to the same type → Unify ((_ -> _), T).

Now prefer the polymorphic scheme in name_types (set via bind_scheme for builtin Ok/Err/Some/None/RuntimeError and user variants) and instantiate it fresh per occurrence — exactly as lookup_var does for ordinary identifiers — falling back to constructor_env only when no scheme is registered.

Full suite 233/233, zero regression. result.affine remains blocked on a separate import-path issue (imported parametric ctor schemes built with fresh_tyvar 0 then generalize, a no-op at level 0) — next slice. Refs #128.

…rns (#128)

check_pattern's PatCon read the monomorphic constructor_env entry and
wrapped it as a 0-tyvar scheme, so every occurrence of a constructor
shared one set of type variables. Two `Ok(_)` patterns in a single
match (e.g. result.affine `apply`'s tuple match) thus forced both
payloads to the same type, yielding `Unify ((_ -> _), T)`.

Now prefer the polymorphic scheme bound in name_types (set via
bind_scheme for builtin Ok/Err/Some/None/RuntimeError and user
variants) and instantiate it fresh per occurrence — exactly as
lookup_var does for ordinary identifiers — falling back to the
constructor_env entry only when no scheme is registered.

Correctness/soundness fix. Full suite 233/233, zero regression.
(result.affine remains blocked on a separate import-path issue:
imported parametric ctor schemes are built with fresh_tyvar 0 then
generalize, a no-op at level 0 — tracked for the next slice.)
Refs #128.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 44 issues detected

Severity Count
🔴 Critical 12
🟠 High 21
🟡 Medium 11

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Stray AI.a2ml in root -- use 0-AI-MANIFEST.a2ml only",
    "type": "banned",
    "file": "AI.a2ml",
    "action": "delete",
    "rule_module": "root_hygiene",
    "severity": "high"
  },
  {
    "reason": "Superseded by 0-AI-MANIFEST.a2ml",
    "type": "banned",
    "file": "AI.djot",
    "action": "delete",
    "rule_module": "root_hygiene",
    "severity": "high"
  },
  {
    "reason": "Issue in quality.yml",
    "type": "missing_workflow",
    "file": "quality.yml",
    "action": "create",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Issue in security-policy.yml",
    "type": "missing_workflow",
    "file": "security-policy.yml",
    "action": "create",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Action hyperpolymath/standards/.github/workflows/governance-reusable.yml@main needs attention",
    "type": "unpinned_action",
    "file": "governance.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "TypeScript file detected -- banned language",
    "type": "banned_language_file",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-deno-test/example/smoke_driver.ts",
    "action": "flag",
    "rule_module": "cicd_rules",
    "severity": "critical"
  },
  {
    "reason": "TypeScript file detected -- banned language",
    "type": "banned_language_file",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-deno-test/cli.ts",
    "action": "flag",
    "rule_module": "cicd_rules",
    "severity": "critical"
  },
  {
    "reason": "TypeScript file detected -- banned language",
    "type": "banned_language_file",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-deno-test/mod.ts",
    "action": "flag",
    "rule_module": "cicd_rules",
    "severity": "critical"
  },
  {
    "reason": "TypeScript file detected -- banned language",
    "type": "banned_language_file",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-deno-test/lib/compile.ts",
    "action": "flag",
    "rule_module": "cicd_rules",
    "severity": "critical"
  },
  {
    "reason": "TypeScript file detected -- banned language",
    "type": "banned_language_file",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-deno-test/lib/runner.ts",
    "action": "flag",
    "rule_module": "cicd_rules",
    "severity": "critical"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

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