Skip to content

Conversation

@kaankacar
Copy link

Prohibit combined unary operators

  • Add semantic error for chained/unparenthesized unary combinations (including parenthesized and negative-literal operands).
  • Update unary/coverage tests to expect errors for sequences like --x, -~x, !!x.

Fixes #82

@0xGeorgii
Copy link
Contributor

@kaankacar Thanks for the contribution. I think that because this check is scope-bounded and not actually a type-check, rather a semantic check, it makes sense to create a new core crate semantic-analysis so the high-level data flow should be like:

parse -> type check -> semantic check -> codegen ...

And there is actually a placeholder function for invoking this new crate:

https://github.com/Inferara/inference/blob/main/core/inference/src/lib.rs#L330

Also, how about parenthesized expressions such as -(~x)) etc.

Since we need to have 3 categories of reporting (info, warning, error), this should also be properly sorted out

Extract the combined unary operator prohibition from the type-checker
into a dedicated `core/semantic-analysis` crate, as this is a semantic
check rather than a type check. The pipeline is now:
  parse -> type check -> semantic check -> codegen

- Create `inference-semantic-analysis` crate with 3-level diagnostic
  reporting (info, warning, error)
- Move `is_prefix_unary` / `CombinedUnaryOperators` logic out of the
  type-checker and into the new semantic analysis pass
- Wire up the placeholder `analyze()` in `core/inference` to invoke the
  new crate
- Handle parenthesized expressions like `-(~x)` and `~-(x)` by
  recursively unwrapping parenthesized nodes
- Add dedicated semantic analysis tests; revert type-checker tests to
  their original expectations

Fixes Inferara#82
@kaankacar
Copy link
Author

Thanks for the feedback @0xGeorgii! I've pushed an update that addresses all of your points:

New semantic-analysis crate

Created core/semantic-analysis as a dedicated crate for scope-bounded checks that aren't type errors. The pipeline is now:

parse -> type check -> semantic check -> codegen

Wired up the placeholder analyze() function. The no-op analyze() in core/inference/src/lib.rs now delegates to inference_semantic_analysis::analyze().

3 categories of reporting

The crate has a diagnostics module with three severity levels (Info, Warning, Error), a SemanticDiagnostic struct carrying severity + message + location, and a SemanticResult that collects diagnostics and can filter by severity.

Parenthesized expressions

Handled — the check recursively unwraps Parenthesized nodes, so cases like -(~x), ~-(x), and --(x) are all caught. Negative numeric literals (e.g., --42) are caught as well.

Type-checker reverted

Removed CombinedUnaryOperators from TypeCheckError and the is_prefix_unary check from type_checker.rs. All type-checker files are back to matching main. The combined unary prohibition now lives entirely in the semantic analysis pass with its own dedicated tests.

Test results

  • inference-type-checker: 71 passed
  • type_checker integration: 408 passed
  • coverage integration: 87 passed
  • semantic_analysis integration: 10 passed

@0xGeorgii 0xGeorgii requested a review from Copilot January 27, 2026 23:17
@0xGeorgii 0xGeorgii added the static analysis Static code analysis label Jan 27, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements semantic analysis to prohibit combined unary operators in the codebase, addressing issue #82. The change introduces a new semantic-analysis module that detects and reports errors for chained or parenthesized unary operator combinations such as --x, !!x, -~x, and -(~x).

Changes:

  • Added a new inference-semantic-analysis crate with diagnostic types and combined unary operator detection logic
  • Integrated the semantic analysis pass into the main compilation pipeline after type checking
  • Created comprehensive test coverage for valid single unary operators and prohibited combined operators

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/semantic-analysis/Cargo.toml New package definition for the semantic analysis crate
core/semantic-analysis/src/lib.rs Core logic for detecting combined unary operators with pattern matching
core/semantic-analysis/src/diagnostics.rs Diagnostic types and severity levels for semantic analysis results
core/inference/src/lib.rs Updated analyze function to run semantic checks and return errors
core/inference/Cargo.toml Added dependency on the new semantic-analysis crate
Cargo.toml Registered the semantic-analysis workspace member
tests/Cargo.toml Added semantic-analysis as a test dependency
tests/src/lib.rs Added semantic_analysis test module
tests/src/semantic_analysis/mod.rs Module declaration for combined_unary tests
tests/src/semantic_analysis/combined_unary.rs Comprehensive test suite for the combined unary operator checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Georgii Plotnikov <accembler@gmail.com>
@0xGeorgii 0xGeorgii requested a review from Copilot January 28, 2026 09:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Georgii Plotnikov <accembler@gmail.com>
@0xGeorgii 0xGeorgii requested a review from Copilot January 28, 2026 09:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Georgii Plotnikov <accembler@gmail.com>
@Inferara Inferara deleted a comment from codecov bot Jan 28, 2026
@0xGeorgii
Copy link
Contributor

@kaankacar Please sync your fork's branch with the latest changes from origin

@kaankacar
Copy link
Author

Synced @0xGeorgii

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

static analysis Static code analysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combined unary operators are prohibited (-~x)

2 participants