Skip to content

feat(type-checker): add undefined-identifier, arity, and arg-type dia…#35

Merged
ggulpari merged 3 commits into
mainfrom
feat/type-checker-diagnostics
Apr 22, 2026
Merged

feat(type-checker): add undefined-identifier, arity, and arg-type dia…#35
ggulpari merged 3 commits into
mainfrom
feat/type-checker-diagnostics

Conversation

@Slashmsu
Copy link
Copy Markdown
Collaborator

…gnostics

Closes the four skipped diagnostics in tests/error-handling.test.ts:

  • Undefined-variable detection via inferIdentifierType with a builtin value seed set (чоп, console, Math, Array, etc.) so existing .som examples keep compiling cleanly.
  • Argument count and argument type validation in inferCallType, with Type.paramTypes / paramNames / paramOptional populated by checkFunctionDeclaration and hoistFunctionDeclaration. Optional params (name?: type) are correctly excluded from the required count.
  • Recursion into function bodies in checkFunctionDeclaration so errors in nested functions are reported. ExpressionStatement and ExportDeclaration cases added to checkStatement.
  • compile() now surfaces parser.getErrors(). In the default mode they are warnings; strict mode promotes them to errors. This lets the typo-keyword test see the "Unexpected token" diagnostic without breaking audit:examples for files with recoverable parse issues.

Incidental fixes uncovered by recursive body walking:

  • Lexer now skips /* ... */ block comments.
  • isAssignable check skips 'unknown' inferred types to avoid cascading false positives for expressions whose inference isn't wired yet.
  • 17-export-patterns.som: default-parameter syntax replaced with optional parameter + in-body default (parser support for default param values remains out of scope here).
  • 09-interfaces.som: type alias Ҳолат renamed to Статус to avoid collision with the reserved keyword ҳолат.

🎉 Pull Request

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality
    to not work as expected)
  • 📚 Documentation update
  • 🔧 Configuration/build changes
  • ✅ Test improvements
  • ♻️ Code refactoring (no functional changes)

Related Issue

Fixes #(issue number)

Changes Made

Testing

  • All existing tests pass (npm test)
  • Added new tests for the changes
  • Tested manually with examples
  • Linting passes (npm run lint)
  • Type checking passes (npm run type-check)

Checklist

  • My code follows the project's code style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Context


📋 License Information

SomonScript is open source software licensed under the MIT License.

By submitting this pull request, you agree that your contributions will be
licensed under the MIT License.

For contribution guidelines, please review:


Thank you for contributing to SomonScript! 🚀

…gnostics

Closes the four skipped diagnostics in tests/error-handling.test.ts:

- Undefined-variable detection via inferIdentifierType with a builtin
  value seed set (чоп, console, Math, Array, etc.) so existing .som
  examples keep compiling cleanly.
- Argument count and argument type validation in inferCallType, with
  Type.paramTypes / paramNames / paramOptional populated by
  checkFunctionDeclaration and hoistFunctionDeclaration. Optional
  params (name?: type) are correctly excluded from the required count.
- Recursion into function bodies in checkFunctionDeclaration so errors
  in nested functions are reported. ExpressionStatement and
  ExportDeclaration cases added to checkStatement.
- compile() now surfaces parser.getErrors(). In the default mode they
  are warnings; strict mode promotes them to errors. This lets the
  typo-keyword test see the "Unexpected token" diagnostic without
  breaking audit:examples for files with recoverable parse issues.

Incidental fixes uncovered by recursive body walking:
- Lexer now skips /* ... */ block comments.
- isAssignable check skips 'unknown' inferred types to avoid cascading
  false positives for expressions whose inference isn't wired yet.
- 17-export-patterns.som: default-parameter syntax replaced with
  optional parameter + in-body default (parser support for default
  param values remains out of scope here).
- 09-interfaces.som: type alias Ҳолат renamed to Статус to avoid
  collision with the reserved keyword ҳолат.
@github-actions
Copy link
Copy Markdown

✅ Tests completed on Node.js 20.x: success

Replaces English JS method names in .som example files with their
Tajik equivalents that already exist in codegen's builtinMappings:

  .toUpperCase() -> .калон()
  .toLowerCase() -> .хурд()
  .length        -> .дарозӣ
  .push()        -> .илова()
  .filter()      -> .филтр()
  .pop()         -> .баровардан()
  .slice()       -> .буридан()
  .map()         -> .харита()
  .forEach()     -> .бароиҲар()
  .join()        -> .пайвастКардан()
  .split()       -> .ҷудокунӣ()
  .indexOf()     -> .индекси()
  .includes()    -> .дорад()
  .repeat()      -> .такрор()
  .sort()        -> .тартиб()
  .toString()    -> .баСатр()
  .trim()        -> .тозаКардан()
  .startsWith()  -> .оғозБо()
  .endsWith()    -> .анҷомБо()
  .replace()     -> .ҷойгузин()
  .concat()      -> .пайвастан()

Adds Tajik aliases for Map / Set methods that were previously only
accessible by their JS name:

  .get()    -> .бозгирифтан()   (тадж: retrieve; avoids a conflict
                                 with the existing .гирифтан->.catch
                                 Promise alias)
  .set()    -> .гузоштан()
  .has()    -> .дорадКалид()
  .size     -> .ҳаҷм
  .delete() -> .нобудКардан()

Replaces the verbose тағйирёбанда keyword with its short-form alias
тағ everywhere in examples so the Tajik surface of the language
reads uniformly across files.
@github-actions
Copy link
Copy Markdown

✅ Tests completed on Node.js 20.x: success

@Slashmsu Slashmsu force-pushed the feat/type-checker-diagnostics branch from 8b758d1 to 882bfee Compare April 22, 2026 14:31
@github-actions
Copy link
Copy Markdown

✅ Tests completed on Node.js 20.x: success

Extract parser-error routing, type-check stage, and code emission into
small helpers so compileInternal reads as a linear pipeline. Behaviour
is unchanged — same tests, same audit.

The sonar complexity lint on compileInternal (16 > 15) is cleared as a
side effect.
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

✅ Tests completed on Node.js 20.x: success

@ggulpari ggulpari enabled auto-merge April 22, 2026 14:34
@ggulpari ggulpari merged commit 04a3e79 into main Apr 22, 2026
15 checks passed
@ggulpari ggulpari deleted the feat/type-checker-diagnostics branch April 22, 2026 14:36
@ggulpari ggulpari restored the feat/type-checker-diagnostics branch April 22, 2026 14:37
@ggulpari ggulpari deleted the feat/type-checker-diagnostics branch April 22, 2026 14:39
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.

2 participants