Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/version hint #51

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Feat/version hint #51

wants to merge 18 commits into from

Conversation

ascandone
Copy link
Contributor

@ascandone ascandone commented Mar 21, 2025

This PR allows the user to specify the required version for the script, so that both in the user CI and the editor, errors will be shown when a feature doesn't satisfy such version

Specs

The version can be specified via a comment like:

// @version interpreter 0.0.15

This will allow the static analysis to emit errors for features which aren't compatible with that version
If the user is targeting the virtual machine implementation, the annotation is

// @version machine

This applies to feature flags as well, for example:

// @feature_flag experimental-oneof 

This will allow the user to specify flags without passing them to the numscript cli- which would lead to a bad UX

To use many flags, comments can be stacked:

// @feature_flag experimental-oneof 
// @feature_flag experimental-account-interpolation

From the runtime perspective, those are backwards-compatible comments without any special meaning, and will be ignored when executing the program

Edge cases

Specifying many version has undefined behaviour
The order/position of the comments is irrelevant
Comments which don't follow the correct syntax are ignored

Copy link

coderabbitai bot commented Mar 21, 2025

Walkthrough

This pull request changes how comments and versioning are handled within the application. The lexer now directs line comments to the HIDDEN channel instead of skipping them. The analysis package has been enhanced with version data in check results and new diagnostics for mismatches and experimental features. Additionally, version-checking logic has been introduced along with corresponding tests. Feature flag references have been centralized in a new flags package, and the parser has been updated to capture and store comments.

Changes

File(s) Change Summary
Lexer.g4, internal/parser/antlrParser/Lexer.interp, internal/parser/antlrParser/lexer.go Modified lexer: Changed LINE_COMMENT handling to route comments to the HIDDEN channel; updated serialized ATN values.
internal/analysis/check.go, internal/analysis/check_test.go, internal/analysis/diagnostic_kind.go, internal/analysis/version_check.go Enhanced version handling: Added a version field to CheckResult, introduced new diagnostics (VersionMismatch, ExperimentalFeature), and implemented version checking methods with corresponding tests.
internal/cmd/run.go, internal/flags/flags.go, internal/interpreter/evaluate_expr.go, internal/interpreter/interpreter.go, internal/interpreter/interpreter_test.go, numscript_test.go Centralized feature flags: Migrated flag references from local definitions and the interpreter package to a dedicated flags package; updated related tests.
internal/parser/ast.go, internal/parser/parser.go, internal/parser/parser_test.go Parser improvements: Added a new Comment type and Comments field in Program, updated the Parse function to collect hidden comments, and introduced tests for comment handling.
internal/parser/version.go, internal/parser/version_test.go Introduced version management: Added a Version interface, concrete types (VersionMachine, VersionInterpreter), parsing functions, version comparison logic, and comprehensive tests.

Sequence Diagram(s)

Loading
sequenceDiagram
  participant Parser
  participant TokenStream
  participant CommentHandler

  Parser->>TokenStream: Retrieve tokens
  TokenStream-->>Parser: Returns visible & hidden tokens
  Parser->>CommentHandler: Check for Hidden tokens
  CommentHandler-->>Parser: Extract Comment (Range, Content)
  Parser->>Program: Append Comment to Comments array
Loading
sequenceDiagram
  participant Expression
  participant CheckResult
  participant Diagnostic

  Expression->>CheckResult: Invoke checkInfixVersion()
  CheckResult->>CheckResult: Call requireVersion() with VersionClause
  alt Version requirement met
    CheckResult-->>Expression: Continue evaluation
  else Version mismatch
    CheckResult->>Diagnostic: Emit VersionMismatch diagnostic
  end

Possibly related PRs

Poem

I'm a rabbit with a twinkle in my eye,
Hopping through tokens as comments fly by.
Version checks and flags now shine so bright,
In the code forest, everything feels just right.
Carrot crunch and code—let’s celebrate tonight! 🐇🍀

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (7)
internal/parser/parser.go (1)

63-70: Consider handling different comment formats.

The implementation correctly processes tokens from the hidden channel to capture comments. However, the code assumes all comments start with exactly two characters (like //), which might not handle block comments (/* */) correctly.

Consider enhancing the comment extraction to handle different comment formats:

-			parsed.Comments = append(parsed.Comments, Comment{
-				Content: tk.GetText()[2:],
-				Range:   tokenToRange(tk),
-			})
+			text := tk.GetText()
+			content := ""
+			if strings.HasPrefix(text, "//") {
+				content = text[2:]
+			} else if strings.HasPrefix(text, "/*") && strings.HasSuffix(text, "*/") {
+				content = text[2 : len(text)-2]
+			} else {
+				content = text
+			}
+			parsed.Comments = append(parsed.Comments, Comment{
+				Content: content,
+				Range:   tokenToRange(tk),
+			})
internal/analysis/diagnostic_kind.go (1)

275-299: Consider revisiting severity for the ExperimentalFeature diagnostic.
Marking the experimental feature usage as an error might be too severe, since the user could interpret this as blocking. A lower severity level (e.g., Warning) might reduce friction for early adopters of experimental features.

internal/analysis/version_check.go (2)

9-21: Clarify function name to better indicate the division check requirement.
Currently, checkInfixVersion only checks whether both sides are numeric. However, it doesn't confirm that the operator is indeed division. Consider making the naming or logic more explicit if the intended scope is only division operators.


39-85: Consider generating all applicable diagnostics in a single pass.
Right now, the loop exits after pushing the first failed clause. If multiple version constraints are applied, you may want to gather each failing clause before returning so that users see a comprehensive view of all mismatches.

internal/parser/version.go (3)

55-75: Add validation for non-negative integers in version parsing.

The function correctly parses semantic versions but doesn't validate that version components are non-negative, which is standard for semantic versioning.

Consider checking for negative values:

func parseSemanticVersion(src string) (bool, int, int, int) {
	parts := strings.Split(src, ".")
	if len(parts) < 3 {
		return false, 0, 0, 0
	}
	major, err := strconv.Atoi(parts[0])
	if err != nil || major < 0 {
		return false, 0, 0, 0
	}

	minor, err := strconv.Atoi(parts[1])
	if err != nil || minor < 0 {
		return false, 0, 0, 0
	}

	patch, err := strconv.Atoi(parts[2])
	if err != nil || patch < 0 {
		return false, 0, 0, 0
	}
	return true, major, minor, patch
}

77-112: Reduce code duplication in string trimming operations.

Both parseVersion and parseFlag functions use the same string trimming operations. This pattern could be extracted to a helper function.

Consider adding a helper function:

func trimComment(comment string) string {
	comment = strings.TrimLeft(comment, " ")
	return strings.TrimRight(comment, " \n")
}

Then use it in both functions:

func parseVersion(comment string) Version {
-	comment = strings.TrimLeft(comment, " ")
-	comment = strings.TrimRight(comment, " \n")
+	comment = trimComment(comment)
	// ...
}

func parseFlag(comment string) string {
-	comment = strings.TrimLeft(comment, " ")
-	comment = strings.TrimRight(comment, " \n")
+	comment = trimComment(comment)
	// ...
}

Also applies to: 124-138


140-150: Consider adding error handling for duplicate feature flags.

The current implementation silently overrides duplicate feature flags. Consider adding logging or validation to detect this scenario.

func (p Program) GetFlags() map[string]struct{} {
	flags := make(map[string]struct{})

	for _, comment := range p.Comments {
		flag := parseFlag(comment.Content)
		if flag != "" {
+			// Optional: Add logging for duplicate flags
+			// _, exists := flags[flag]
+			// if exists {
+			//     log.Printf("Warning: Duplicate feature flag found: %s", flag)
+			// }
			flags[flag] = struct{}{}
		}
	}
	return flags
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7e4f3 and 134c83c.

⛔ Files ignored due to path filters (2)
  • internal/parser/__snapshots__/parser_fault_tolerance_test.snap is excluded by !**/*.snap, !**/*.snap
  • internal/parser/__snapshots__/parser_test.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (18)
  • Lexer.g4 (1 hunks)
  • internal/analysis/check.go (5 hunks)
  • internal/analysis/check_test.go (2 hunks)
  • internal/analysis/diagnostic_kind.go (2 hunks)
  • internal/analysis/version_check.go (1 hunks)
  • internal/cmd/run.go (3 hunks)
  • internal/flags/flags.go (1 hunks)
  • internal/interpreter/batch_balances_query.go (1 hunks)
  • internal/interpreter/evaluate_expr.go (2 hunks)
  • internal/interpreter/interpreter.go (5 hunks)
  • internal/interpreter/interpreter_test.go (16 hunks)
  • internal/parser/antlrParser/Lexer.interp (1 hunks)
  • internal/parser/antlrParser/lexer.go (2 hunks)
  • internal/parser/ast.go (1 hunks)
  • internal/parser/parser.go (1 hunks)
  • internal/parser/parser_test.go (1 hunks)
  • internal/parser/version.go (1 hunks)
  • internal/parser/version_test.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (8)
internal/parser/parser.go (3)
internal/parser/ast.go (1) (1)
  • Comment (317-320)
internal/lsp/bindings.go (2) (2)
  • Comment (5170-5170)
  • Range (3072-3081)
internal/parser/range.go (1) (1)
  • Range (13-16)
internal/parser/ast.go (2)
internal/parser/range.go (1) (1)
  • Range (13-16)
internal/lsp/bindings.go (2) (2)
  • Range (3072-3081)
  • Comment (5170-5170)
internal/interpreter/evaluate_expr.go (2)
internal/interpreter/interpreter.go (7) (7)
  • st (263-268)
  • st (270-275)
  • st (277-314)
  • st (316-330)
  • st (332-365)
  • st (367-415)
  • st (975-997)
internal/flags/flags.go (1) (1)
  • ExperimentalAccountInterpolationFlag (8-8)
internal/interpreter/interpreter.go (1)
internal/flags/flags.go (2) (2)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
internal/cmd/run.go (1)
internal/flags/flags.go (3) (3)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalAccountInterpolationFlag (8-8)
internal/analysis/diagnostic_kind.go (4)
internal/parser/version.go (1) (1)
  • Version (9-12)
internal/interpreter/interpreter_error.go (17) (17)
  • e (17-19)
  • e (26-28)
  • e (35-37)
  • e (45-47)
  • e (55-57)
  • e (64-66)
  • e (74-76)
  • e (83-85)
  • e (92-94)
  • e (102-104)
  • e (111-113)
  • e (121-123)
  • e (130-132)
  • e (138-140)
  • e (147-149)
  • e (156-158)
  • ExperimentalFeature (197-200)
internal/interpreter/value.go (2) (2)
  • String (17-17)
  • String (27-27)
internal/lsp/bindings.go (1) (1)
  • String (5310-5310)
internal/analysis/version_check.go (2)
internal/analysis/check.go (1) (1)
  • CheckResult (94-105)
internal/analysis/diagnostic_kind.go (5) (5)
  • _ (17-17)
  • VersionMismatch (276-279)
  • VersionMismatch (285-287)
  • ExperimentalFeature (289-291)
  • ExperimentalFeature (297-299)
internal/interpreter/interpreter_test.go (1)
internal/flags/flags.go (3) (3)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalAccountInterpolationFlag (8-8)
🔇 Additional comments (47)
internal/interpreter/batch_balances_query.go (1)

60-60: Clean and simplified syntax!

The code now uses a more concise version of slices.Contains without explicit type parameters, allowing the Go compiler to infer the types automatically. This improves readability while maintaining the same functionality.

internal/flags/flags.go (1)

1-9: Good centralization of feature flags!

Creating a dedicated package for feature flags is an excellent architectural decision. This centralization makes feature flag management more maintainable and creates a single source of truth for these flags across the codebase.

The type alias FeatureFlag = string provides good semantic meaning while allowing string constants to be used as flags. The naming of the constants is clear and descriptive.

internal/cmd/run.go (5)

11-11: Appropriate import for the new flags package.

Adding the import for the flags package is necessary for the refactoring of feature flag references.


125-125: Good refactoring to use centralized feature flags.

Using the flag from the dedicated flags package instead of directly from the interpreter package improves code organization.


128-128: Good refactoring to use centralized feature flags.

Using the flag from the dedicated flags package instead of directly from the interpreter package improves code organization.


131-131: Good refactoring to use centralized feature flags.

Using the flag from the dedicated flags package instead of directly from the interpreter package improves code organization.


212-214: Good refactoring of command flag definitions.

Using the flag constants from the dedicated flags package in the command flag definitions ensures consistency between the flag names used in the command-line interface and the internal code.

internal/interpreter/evaluate_expr.go (2)

7-7: Appropriate import for the new flags package.

Adding the import for the flags package is necessary for the refactoring of feature flag references.


23-23: Good refactoring to use centralized feature flags.

Using the flag from the dedicated flags package instead of directly from the interpreter package improves code organization and maintainability.

internal/interpreter/interpreter.go (5)

10-10: Added new import for feature flags package.

The feature flags have been centralized in the flags package, which is a good practice for maintainability and consistency.


476-476: Updated feature flag reference to use the centralized package.

The code now references flags.ExperimentalOneofFeatureFlag instead of a local constant, maintaining the same functionality while improving code organization.


577-577: Updated feature flag reference to use the centralized package.

This instance of checking the "oneof" feature flag has been updated to use the centralized flag definition.


715-715: Updated feature flag reference to use the centralized package.

Another reference to the "oneof" feature flag was correctly updated to use the flags package.


909-909: Updated overdraft feature flag reference to use the centralized package.

The experimental overdraft function feature flag reference has been updated to use the centralized flags package.

internal/interpreter/interpreter_test.go (4)

8-8: Added import for the flags package.

Added import for the centralized feature flags package, which is necessary for the refactored feature flag references throughout the test file.


3422-3422: Updated overdraft feature flag references in tests.

Feature flag references in the overdraft function tests have been updated to use the centralized flags package. This ensures consistency with the implementation code.

Also applies to: 3445-3445, 3469-3469, 3504-3504


3662-3662: Updated oneof feature flag references in tests.

All references to the experimental "oneof" feature flag have been updated to use the centralized flags package across multiple test cases, maintaining consistency with the implementation code.

Also applies to: 3687-3687, 3710-3710, 3737-3737, 3760-3760, 3785-3785, 3811-3811, 3837-3837


3889-3889: Updated account interpolation feature flag references in tests.

References to the experimental account interpolation feature flag have been updated to use the centralized flags package, ensuring consistency with the implementation.

Also applies to: 3919-3919, 3949-3949

internal/parser/antlrParser/lexer.go (2)

151-152: Line comment handling now routes to HIDDEN channel

The changes in the serialized ATN (Abstract Syntax Tree) reflect the corresponding grammar change in Lexer.g4. Instead of skipping line comments entirely, they're now routed to the HIDDEN channel, making them accessible for later processing by the parser.


218-219: Mode transitions in lexer updated for consistency

These ATN state changes to the lexer's push mode behavior for ACCOUNT_START and COLON tokens align with the modified comment handling approach. The transition data now properly maintains token channel information.

Also applies to: 226-227

internal/parser/antlrParser/Lexer.interp (1)

142-142: ATN serialization updated to match new comment handling

The changes to the serialized ATN (Abstract Syntax Tree) in this file are compiler-generated reflections of the grammar changes in Lexer.g4, ensuring that line comments are properly routed to the HIDDEN channel.

Lexer.g4 (1)

5-5: Line comments now preserved instead of skipped

This is the core change that enables comment preservation in the lexer. By routing line comments to the HIDDEN channel instead of skipping them, they become accessible to the parser for further processing, likely to support version hints or other metadata specified in comments.

This is a well-established pattern in language parsers when comments need to be preserved for documentation or semantic purposes.

internal/parser/parser_test.go (1)

441-454: New test validating comment handling

This test ensures that line comments are properly preserved during parsing. The test parses a script with line comments before function calls and verifies that the parser correctly processes it without errors. The snapshot validation confirms that the comment content is properly captured in the AST.

This test appropriately validates the new comment handling behavior introduced by the lexer changes.

internal/parser/ast.go (2)

317-320: Well-structured Comment type with clear purpose.

The new Comment struct definition is clean and follows the established pattern of embedding Range for position tracking.


325-325: Good addition to Program struct.

Adding the Comments field to the Program struct allows for preserving comments in the AST, which is essential for the new versioning functionality.

internal/analysis/check.go (5)

95-95: Good addition of version field to CheckResult.

Adding the version field to CheckResult is a clean way to make version information available during analysis.


145-145: Proper initialization of version field.

The initialization of the version field in newCheckResult properly retrieves the version from the program being analyzed.


356-357: Well-placed version check for division operator.

The checkInfixVersion call for division operators is appropriately placed to validate version compatibility before processing the operation.


479-480: Version verification for oneof source construct.

The checkOneofVersion call for SourceOneof ensures that this feature is only used in compatible versions.


635-636: Version verification for oneof destination construct.

The checkOneofVersion call for DestinationOneof ensures that this feature is only used in compatible versions.

internal/parser/version_test.go (6)

10-16: Good test for machine version parsing.

This test correctly verifies that machine version declarations are parsed properly from comments.


18-28: Good test for interpreter version parsing.

This test verifies that interpreter versions with semantic versioning (major.minor.patch) are correctly parsed from comments.


30-39: Good edge case test for version parsing.

Testing that version information can be extracted even when it's not in the first comment is a good edge case to cover.


41-47: Good test for invalid version handling.

This test verifies that invalid version strings are handled gracefully by returning nil.


49-61: Comprehensive test for feature flag parsing.

This test effectively verifies that multiple feature flags can be parsed from comments and stored correctly.


63-175: Thorough version comparison tests.

The test suite for GtEq is comprehensive, covering all relevant comparison scenarios including same version, different major/minor/patch versions, and edge cases.

internal/analysis/diagnostic_kind.go (1)

8-8: No concerns for the new parser import.
Everything looks standard here, and the reference aligns with the usage of parser types below.

internal/analysis/version_check.go (2)

23-30: Good introduction of checkOneofVersion logic.
The method properly calls requireVersion with both a version and a feature flag. No issues spotted with logic or structure.


34-37: Struct encapsulation looks clean and extensible.
VersionClause effectively binds the version with an optional feature flag. Implementation is straightforward and will be easy to maintain.

internal/analysis/check_test.go (6)

7-7: Import usage looks correct.
The flags import is properly leveraged in the new tests.


675-697: TestDoNoCheckVersionWhenNotSpecified is well-rounded.
It confirms that no version is treated as valid, returning zero diagnostics. This ensures backward compatibility for users not specifying versions.


699-728: TestRequireVersionForInfixDiv effectively checks machine vs. interpreter mismatch.
This test adequately proves that a machine version triggers a mismatch when the code requires an interpreter version ≥0.0.15.


730-760: TestRequireVersionForInfixDivWhenVersionLt elegantly covers lower interpreter versions.
Great demonstration of how a version below the threshold rejects the use of division in the expression.


762-784: TestRequireFlagForOneofWhenMissing confirms the need for the experimental flag.
This is an excellent validation that ensures the user is shown the correct diagnostic if the flag is not set.


786-801: TestRequireFlagForOneofWhenGiven illustrates successful usage of the feature flag.
Proper coverage of the enabled scenario with no diagnostics, ensuring the code respects experimental feature toggles.

internal/parser/version.go (2)

9-12: Simple and well-defined interface design.

The Version interface provides a clean abstraction with a marker method for type identification and a string representation method.


114-122:

✅ Verification successful

Verify version handling consistency across the codebase.

The GetVersion method returns the first valid version it finds. Ensure that this aligns with the expected behavior if multiple version tags are present in the code.


🏁 Script executed:

#!/bin/bash
# Check if there are any test cases covering multiple version tags
# and verify the expected behavior

# Look for test cases that might test multiple version scenarios
rg -l "TestVersion|test.*version|Version.*test" --type go

Length of output: 123


Version handling behavior verified against test cases.

The tests in internal/parser/version_test.go and internal/analysis/check_test.go confirm that when multiple version tags are present, the GetVersion method correctly returns the first valid version it encounters. This aligns with the intended design, and no further changes are required at this time.

Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 68.88889% with 70 lines in your changes missing coverage. Please review.

Project coverage is 62.52%. Comparing base (0d7e4f3) to head (2a22d35).

Files with missing lines Patch % Lines
internal/parser/version.go 60.20% 30 Missing and 9 partials ⚠️
internal/analysis/version_check.go 83.75% 12 Missing and 1 partial ⚠️
internal/analysis/diagnostic_kind.go 0.00% 8 Missing ⚠️
internal/cmd/run.go 0.00% 8 Missing ⚠️
internal/analysis/check.go 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #51      +/-   ##
==========================================
+ Coverage   62.25%   62.52%   +0.26%     
==========================================
  Files          33       35       +2     
  Lines        7235     7439     +204     
==========================================
+ Hits         4504     4651     +147     
- Misses       2505     2553      +48     
- Partials      226      235       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
internal/parser/version.go (1)

42-53: ⚠️ Potential issue

Fix comparison logic in GtEq method.

The current implementation has a logical error in the version comparison. When major versions are equal but minor versions differ (e.g., comparing 1.2.0 with 1.1.0), it should return true if the first version's minor is greater, but the function is missing this check.

Apply this fix:

func (v VersionInterpreter) GtEq(other VersionInterpreter) bool {
	if v.Major > other.Major {
		return true
	}
	if v.Major < other.Major {
		return false
	}
+	if v.Minor > other.Minor {
+		return true
+	}
	if v.Minor < other.Minor {
		return false
	}
	return v.Patch >= other.Patch
}
🧹 Nitpick comments (4)
internal/flags/flags.go (1)

1-11: Created centralized feature flags package

This new file creates a dedicated package for feature flag definitions, which is an excellent architectural improvement. Centralizing feature flags makes them easier to manage, document, and evolve over time.

The package defines a type alias for feature flags and establishes constants for all experimental features, ensuring consistent naming and string values across the codebase.

Consider adding documentation comments to each feature flag explaining:

  1. What functionality the flag enables
  2. When/if it's expected to become a standard feature
  3. Any risks or limitations associated with enabling it

This would make it easier for developers to understand the purpose and status of each flag.

internal/parser/version.go (3)

55-75: Add tests for edge cases in parseSemanticVersion.

This function handles critical version parsing logic but lacks test coverage for failure scenarios like invalid formats or non-numeric values.

Consider adding tests that verify:

  1. Handling of incomplete version strings (fewer than 3 components)
  2. Handling of non-numeric version components
  3. Edge cases like "1.2.3.4" (extra components)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 58-59: internal/parser/version.go#L58-L59
Added lines #L58 - L59 were not covered by tests


[warning] 62-63: internal/parser/version.go#L62-L63
Added lines #L62 - L63 were not covered by tests


[warning] 67-68: internal/parser/version.go#L67-L68
Added lines #L67 - L68 were not covered by tests


[warning] 72-73: internal/parser/version.go#L72-L73
Added lines #L72 - L73 were not covered by tests


114-122: Consider returning a default version instead of nil.

The method GetVersion() returns nil when no version is found, which could lead to nil pointer dereferences downstream if not handled carefully.

Consider returning a default version (like VersionMachine{}) or clearly documenting that nil is a possible return value that must be checked.


77-112: Add test coverage for parseVersion function.

This function handles version detection from comments but lacks test coverage for several branches.

Add tests covering:

  1. Comments with different version formats
  2. Invalid semantic version values
  3. Comments without the @Version tag
  4. Edge cases like empty comments or malformed inputs
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 83-84: internal/parser/version.go#L83-L84
Added lines #L83 - L84 were not covered by tests


[warning] 95-96: internal/parser/version.go#L95-L96
Added lines #L95 - L96 were not covered by tests


[warning] 100-101: internal/parser/version.go#L100-L101
Added lines #L100 - L101 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 134c83c and c601a68.

⛔ Files ignored due to path filters (2)
  • internal/parser/__snapshots__/parser_fault_tolerance_test.snap is excluded by !**/*.snap, !**/*.snap
  • internal/parser/__snapshots__/parser_test.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (18)
  • Lexer.g4 (1 hunks)
  • internal/analysis/check.go (5 hunks)
  • internal/analysis/check_test.go (2 hunks)
  • internal/analysis/diagnostic_kind.go (2 hunks)
  • internal/analysis/version_check.go (1 hunks)
  • internal/cmd/run.go (3 hunks)
  • internal/flags/flags.go (1 hunks)
  • internal/interpreter/evaluate_expr.go (3 hunks)
  • internal/interpreter/interpreter.go (6 hunks)
  • internal/interpreter/interpreter_test.go (20 hunks)
  • internal/parser/antlrParser/Lexer.interp (1 hunks)
  • internal/parser/antlrParser/lexer.go (2 hunks)
  • internal/parser/ast.go (1 hunks)
  • internal/parser/parser.go (1 hunks)
  • internal/parser/parser_test.go (1 hunks)
  • internal/parser/version.go (1 hunks)
  • internal/parser/version_test.go (1 hunks)
  • numscript_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • Lexer.g4
  • internal/parser/parser.go
  • internal/parser/parser_test.go
  • internal/parser/version_test.go
  • internal/parser/ast.go
  • internal/parser/antlrParser/lexer.go
  • internal/interpreter/evaluate_expr.go
  • internal/parser/antlrParser/Lexer.interp
🧰 Additional context used
🧬 Code Definitions (7)
internal/interpreter/interpreter.go (1)
internal/flags/flags.go (3) (3)
  • ExperimentalMidScriptFunctionCall (9-9)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
internal/analysis/diagnostic_kind.go (4)
internal/parser/version.go (1) (1)
  • Version (9-12)
internal/interpreter/interpreter_error.go (17) (17)
  • e (17-19)
  • e (26-28)
  • e (35-37)
  • e (45-47)
  • e (55-57)
  • e (64-66)
  • e (74-76)
  • e (83-85)
  • e (92-94)
  • e (102-104)
  • e (111-113)
  • e (121-123)
  • e (130-132)
  • e (138-140)
  • e (147-149)
  • e (156-158)
  • ExperimentalFeature (197-200)
internal/interpreter/value.go (2) (2)
  • String (17-17)
  • String (27-27)
internal/lsp/bindings.go (1) (1)
  • String (5310-5310)
numscript_test.go (1)
internal/flags/flags.go (2) (2)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalMidScriptFunctionCall (9-9)
internal/analysis/version_check.go (2)
internal/analysis/check.go (17) (17)
  • res (155-181)
  • res (183-209)
  • res (227-285)
  • res (291-295)
  • res (297-305)
  • res (307-321)
  • res (323-326)
  • res (328-394)
  • res (396-409)
  • res (411-420)
  • res (422-429)
  • res (431-538)
  • res (549-586)
  • res (589-621)
  • res (623-682)
  • res (684-691)
  • CheckResult (94-105)
internal/analysis/diagnostic_kind.go (5) (5)
  • _ (17-17)
  • VersionMismatch (276-279)
  • VersionMismatch (285-287)
  • ExperimentalFeature (289-291)
  • ExperimentalFeature (297-299)
internal/analysis/check_test.go (3)
internal/analysis/check.go (1) (1)
  • Diagnostic (88-92)
internal/analysis/diagnostic_kind.go (2) (2)
  • VersionMismatch (276-279)
  • VersionMismatch (285-287)
internal/parser/version.go (2) (2)
  • VersionMachine (14-14)
  • NewVersionInterpreter (28-34)
internal/interpreter/interpreter_test.go (1)
internal/flags/flags.go (4) (4)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalAccountInterpolationFlag (8-8)
  • ExperimentalMidScriptFunctionCall (9-9)
internal/cmd/run.go (1)
internal/flags/flags.go (4) (4)
  • ExperimentalOverdraftFunctionFeatureFlag (6-6)
  • ExperimentalOneofFeatureFlag (7-7)
  • ExperimentalAccountInterpolationFlag (8-8)
  • ExperimentalMidScriptFunctionCall (9-9)
🪛 GitHub Check: codecov/patch
internal/analysis/check.go

[warning] 640-641: internal/analysis/check.go#L640-L641
Added lines #L640 - L641 were not covered by tests

internal/analysis/diagnostic_kind.go

[warning] 281-282: internal/analysis/diagnostic_kind.go#L281-L282
Added lines #L281 - L282 were not covered by tests


[warning] 285-286: internal/analysis/diagnostic_kind.go#L285-L286
Added lines #L285 - L286 were not covered by tests


[warning] 293-294: internal/analysis/diagnostic_kind.go#L293-L294
Added lines #L293 - L294 were not covered by tests


[warning] 297-298: internal/analysis/diagnostic_kind.go#L297-L298
Added lines #L297 - L298 were not covered by tests

internal/analysis/version_check.go

[warning] 51-60: internal/analysis/version_check.go#L51-L60
Added lines #L51 - L60 were not covered by tests


[warning] 75-76: internal/analysis/version_check.go#L75-L76
Added lines #L75 - L76 were not covered by tests

internal/parser/version.go

[warning] 16-16: internal/parser/version.go#L16
Added line #L16 was not covered by tests


[warning] 18-19: internal/parser/version.go#L18-L19
Added lines #L18 - L19 were not covered by tests


[warning] 28-33: internal/parser/version.go#L28-L33
Added lines #L28 - L33 were not covered by tests


[warning] 36-36: internal/parser/version.go#L36
Added line #L36 was not covered by tests


[warning] 38-39: internal/parser/version.go#L38-L39
Added lines #L38 - L39 were not covered by tests


[warning] 58-59: internal/parser/version.go#L58-L59
Added lines #L58 - L59 were not covered by tests


[warning] 62-63: internal/parser/version.go#L62-L63
Added lines #L62 - L63 were not covered by tests


[warning] 67-68: internal/parser/version.go#L67-L68
Added lines #L67 - L68 were not covered by tests


[warning] 72-73: internal/parser/version.go#L72-L73
Added lines #L72 - L73 were not covered by tests


[warning] 83-84: internal/parser/version.go#L83-L84
Added lines #L83 - L84 were not covered by tests


[warning] 95-96: internal/parser/version.go#L95-L96
Added lines #L95 - L96 were not covered by tests


[warning] 100-101: internal/parser/version.go#L100-L101
Added lines #L100 - L101 were not covered by tests


[warning] 130-131: internal/parser/version.go#L130-L131
Added lines #L130 - L131 were not covered by tests


[warning] 134-135: internal/parser/version.go#L134-L135
Added lines #L134 - L135 were not covered by tests

internal/cmd/run.go

[warning] 126-126: internal/cmd/run.go#L126
Added line #L126 was not covered by tests


[warning] 129-129: internal/cmd/run.go#L129
Added line #L129 was not covered by tests


[warning] 132-132: internal/cmd/run.go#L132
Added line #L132 was not covered by tests


[warning] 135-135: internal/cmd/run.go#L135
Added line #L135 was not covered by tests


[warning] 217-220: internal/cmd/run.go#L217-L220
Added lines #L217 - L220 were not covered by tests

🔇 Additional comments (28)
internal/cmd/run.go (3)

11-11: Import of flags package added for feature flag references

The import of the new flags package centralizes feature flag references. This is a good practice for better organization and maintainability of feature flags.


217-220:

✅ Verification successful

CLI flag definitions now use the flags package constants

The CLI flag definitions now directly reference the constants from the flags package. This ensures consistency between CLI flags and internal feature flag references.


🏁 Script executed:

#!/bin/bash
# Check the CLI flag execution to verify the code changes work as expected

# Look for any test files that verify the CLI flag behavior
fd ".*test.*\.go" | xargs rg -l "experimental.*flag" 

# Check if any tests actually validate this code path
rg -A 2 -B 2 "RunWithFeatureFlags|cmd\.Flags\(\)" --type go

Length of output: 2990


CLI flags now correctly reference the flags package constants

The tests confirm that the CLI flag definitions (including experimental overdraft, oneof, account interpolation, and mid-script function call flags) are properly wired up as intended. No issues were found in the updated flag usage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 217-220: internal/cmd/run.go#L217-L220
Added lines #L217 - L220 were not covered by tests


126-136:

✅ Verification successful

Updated feature flag references to use centralized flags package

Feature flag references have been migrated from the interpreter package to the new flags package, maintaining consistent behavior while improving code organization.


🏁 Script executed:

#!/bin/bash
# Verify that all feature flag references in the codebase now use the flags package consistently

# Check for any remaining references to interpreter package feature flags
rg -l "interpreter\.Experimental.*Flag|interpreter\.Experimental.*Function" --type go

# Count the number of references to the flags package to verify adoption
rg -c "flags\.Experimental" --type go

Length of output: 362


Feature flags now consistently reference the centralized flags package

The updated code in internal/cmd/run.go correctly replaces the interpreter package feature flag references with those from the new flags package. Our grep results confirm that no residual references to interpreter.Experimental… exist, and the use of flags.Experimental is consistent across the codebase (e.g., in internal/interpreter/evaluate_expr.go, internal/interpreter/interpreter_test.go, etc.).

No further changes are required.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 126-126: internal/cmd/run.go#L126
Added line #L126 was not covered by tests


[warning] 129-129: internal/cmd/run.go#L129
Added line #L129 was not covered by tests


[warning] 132-132: internal/cmd/run.go#L132
Added line #L132 was not covered by tests


[warning] 135-135: internal/cmd/run.go#L135
Added line #L135 was not covered by tests

numscript_test.go (3)

10-10: Import of flags package added for test references

The flags package is now imported in the test file, replacing the interpreter package as the source of feature flag definitions.


170-170: Updated feature flag reference in TestGetBalancesOneof

The test now uses the feature flag from the flags package instead of the interpreter package, maintaining the same behavior while aligning with the architectural changes.


446-446: Updated feature flag references for mid-script function calls

Both test cases now use the feature flag from the flags package, ensuring consistency with the new architectural approach.

Also applies to: 497-497

internal/analysis/check.go (5)

95-95: Added version field to CheckResult struct

A version field has been added to the CheckResult struct to track and validate the version of the program being analyzed. This is essential for providing version-specific diagnostics.


145-145: Initialize the version field in newCheckResult

The version is now properly initialized when creating a new CheckResult by calling program.GetVersion(), ensuring that version information is always available for subsequent checks.


358-359: Added version check for division operator

The code now validates if the division operator is supported in the current version, helping prevent usage of features that might not be available in earlier versions.


484-485: Added version check for source oneof construct

The code now validates if the oneof construct is supported in the current version for source specifications, preventing usage where it's not supported.


640-641:

❓ Verification inconclusive

Added version check for destination oneof construct

The code now validates if the oneof construct is supported in the current version for destination specifications, preventing usage where it's not supported.


🏁 Script executed:

#!/bin/bash
# Check test coverage for the destination oneof version check

# Look for tests that cover this code path
rg -B 5 -A 5 "checkOneofVersion.*destination" --type go
rg -B 5 -A 5 "DestinationOneof" "test.*\.go"

Length of output: 765


Action Required: Manual Verification of Test Coverage for Oneof Version Check

The oneof version check in internal/analysis/check.go (lines ~640–641) is confirmed to be present. However, our search did not reveal any tests specifically covering this functionality. Please verify whether tests exist under a different naming convention (e.g., *_test.go) or ensure that unit tests are added to validate that the oneof construct is supported only in appropriate versions, preventing unintended usage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 640-641: internal/analysis/check.go#L640-L641
Added lines #L640 - L641 were not covered by tests

internal/interpreter/interpreter.go (3)

10-10: Good refactoring to centralize feature flags

Adding the import for the new flags package is a clean approach to centralize feature flag definitions.


142-142: Updated feature flag reference

Correctly updated to use the centralized flag from the flags package.


502-502: Consistent use of centralized feature flags

All instances of feature flag references have been consistently updated to use the new flags package.

Also applies to: 603-603, 935-935

internal/analysis/diagnostic_kind.go (2)

276-287:

✅ Verification successful

Well-structured version mismatch diagnostic

The VersionMismatch struct and its methods are well-designed and follow the same pattern as other diagnostic types in this file. The error message is clear and provides actionable information.

The static analysis indicates these methods aren't covered by tests:


🏁 Script executed:

#!/bin/bash
# Check if there are any tests that use VersionMismatch
grep -r "VersionMismatch" --include="*_test.go" .

Length of output: 189


Approval: VersionMismatch Diagnostic Implementation Verified

The VersionMismatch diagnostic is well-designed and follows the established pattern. The previously noted potential test coverage gap has been resolved, as evidence in internal/analysis/check_test.go confirms that tests indeed reference VersionMismatch.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 281-282: internal/analysis/diagnostic_kind.go#L281-L282
Added lines #L281 - L282 were not covered by tests


[warning] 285-286: internal/analysis/diagnostic_kind.go#L285-L286
Added lines #L285 - L286 were not covered by tests


289-299:

✅ Verification successful

Good implementation of experimental feature diagnostic

The ExperimentalFeature diagnostic provides clear guidance to users on how to enable experimental features with a comment. This is a good user experience improvement.

The static analysis indicates these methods aren't covered by tests:


🏁 Script executed:

#!/bin/bash
# Check if there are any tests that use ExperimentalFeature
grep -r "ExperimentalFeature" --include="*_test.go" .

Length of output: 330


Approved: Experimental Feature Diagnostic Implementation Meets Test Coverage Expectations

The implementation in internal/analysis/diagnostic_kind.go (lines 289-299) clearly instructs users on how to enable experimental features through an in-script comment, demonstrating an excellent user experience improvement. The additional test references found in both internal/analysis/check_test.go and internal/interpreter/interpreter_test.go confirm that the ExperimentalFeature type—and by extension its Message and Severity methods—are now covered by tests. No further changes are required.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 293-294: internal/analysis/diagnostic_kind.go#L293-L294
Added lines #L293 - L294 were not covered by tests


[warning] 297-298: internal/analysis/diagnostic_kind.go#L297-L298
Added lines #L297 - L298 were not covered by tests

internal/analysis/version_check.go (4)

8-21: Good implementation of version checking for infix expressions

The checkInfixVersion function correctly identifies when an infix expression requires a newer version, with a special exemption for number literals.


23-30: Well-structured feature flag check for oneof

The checkOneofVersion function properly combines version checking with feature flag validation, using the VersionClause struct.


34-37: Good design for version requirements

The VersionClause struct elegantly combines a version requirement with an optional feature flag.


39-86:

✅ Verification successful

Comprehensive version checking logic

The requireVersion method handles different version types appropriately and provides clear diagnostics when version requirements aren't met. It also includes feature flag validation.

Some code paths seem to be uncovered by tests according to static analysis:


🏁 Script executed:

#!/bin/bash
# Check test coverage for the VersionMachine case
grep -r "VersionMachine" --include="*_test.go" . | grep -v "NewVersionMachine"

Length of output: 258


Verified VersionMachine Test Coverage

The version checking logic handles both machine and interpreter version requirements correctly, with proper feature flag validation and diagnostics. The static analysis concern regarding the VersionMachine branch is resolved—existing tests in both ./internal/analysis/check_test.go and ./internal/parser/version_test.go confirm that this code path is covered.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 51-60: internal/analysis/version_check.go#L51-L60
Added lines #L51 - L60 were not covered by tests


[warning] 75-76: internal/analysis/version_check.go#L75-L76
Added lines #L75 - L76 were not covered by tests

internal/analysis/check_test.go (5)

676-697: Good test for unspecified version

This test verifies that no diagnostics are generated when no version is specified, which is the correct behavior.


699-728: Comprehensive test for machine version

This test correctly verifies that using the machine version with an infix division operation generates the appropriate version mismatch diagnostic.


730-760: Good test for version comparison

This test ensures that using a version that's less than the required version generates a version mismatch diagnostic, which is important for backward compatibility.


762-784: Proper test for missing feature flag

This test validates that using the oneof feature without the corresponding feature flag generates the appropriate diagnostic.


786-801: Complete test suite with positive case

This test verifies that the oneof feature works correctly when the appropriate feature flag is provided, completing the test coverage for this feature.

internal/parser/version.go (1)

28-39:

❓ Verification inconclusive

Add tests for VersionInterpreter constructor and methods.

The NewVersionInterpreter function and associated methods lack test coverage, which is important for ensuring version comparisons work correctly.


🏁 Script executed:

#!/bin/bash
# Check if there are any tests for VersionInterpreter implementations
rg -A 2 "Test.*VersionInterpreter" --type go

Length of output: 46


🏁 Script executed:

#!/bin/bash
# Check if there are any test files that reference VersionInterpreter in test files.
rg -l 'VersionInterpreter' -g '*_test.go'

Length of output: 105


🏁 Script executed:

#!/bin/bash
# Check if NewVersionInterpreter or its methods (e.g., String) are referenced/tested in internal/parser/version_test.go
rg -n "(NewVersionInterpreter|VersionInterpreter).*\(" internal/parser/version_test.go

Length of output: 88


Action: Add Explicit Tests for VersionInterpreter Functionality

The current test coverage for the VersionInterpreter appears incomplete. Although the repository contains two test files referencing "VersionInterpreter" (i.e., internal/parser/version_test.go and internal/analysis/check_test.go), our searches indicate that none of these tests explicitly call or validate the behavior of the NewVersionInterpreter constructor or its methods (version() and String()). This raises concerns about whether version comparisons and string formatting are adequately verified.

  • Files requiring attention:
    • internal/parser/version.go (constructor and methods implementation)
    • Test files (especially internal/parser/version_test.go) should include tests that:
      • Confirm that NewVersionInterpreter correctly assigns the major, minor, and patch fields.
      • Verify that the String() method produces the expected output, e.g., "interpreter <major>.<minor>.<patch>".
      • Clarify the role or intended behavior of the version() method if it should exhibit functional behavior.

Please add unit tests to explicitly cover these functionalities.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 28-33: internal/parser/version.go#L28-L33
Added lines #L28 - L33 were not covered by tests


[warning] 36-36: internal/parser/version.go#L36
Added line #L36 was not covered by tests


[warning] 38-39: internal/parser/version.go#L38-L39
Added lines #L38 - L39 were not covered by tests

internal/interpreter/interpreter_test.go (2)

8-8: Well-structured import of the centralized flags package.

Good refactoring to import the new flags package which centralizes feature flag constants.


3517-3517: Correctly updated feature flag references.

The changes from machine.ExperimentalOverdraftFunctionFeatureFlag to flags.ExperimentalOverdraftFunctionFeatureFlag help centralize feature flag definitions.

Comment on lines +16 to +20
func (v VersionMachine) version() {}

func (v VersionMachine) String() string {
return "machine"
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Add unit tests for VersionMachine methods.

The static analysis shows these methods aren't covered by tests, which could lead to undetected regressions in the future.


🏁 Script executed:

#!/bin/bash
# Check if there are any tests for VersionMachine implementations
rg -A 2 "Test.*VersionMachine" --type go

Length of output: 42


Please run this script to verify if any tests cover the VersionMachine methods. If the output remains empty, it confirms that these methods currently lack test coverage and unit tests should be added.


🏁 Script executed:

#!/bin/bash
# Check for any test files explicitly mentioning VersionMachine,
# which might indicate that tests for VersionMachine methods exist.
rg -l "VersionMachine" --glob '*_test.go'

Length of output: 227


ACTION: Add Unit Tests for VersionMachine Methods

The static analysis indicates that while there are test files referencing VersionMachine (specifically internal/parser/version_test.go and internal/analysis/check_test.go), they do not appear to exercise the actual implementations of VersionMachine.version() and VersionMachine.String(). This omission might lead to undetected regressions if these methods change in the future.

Recommendations:

  • Add explicit unit tests targeting:
    • The version() method.
    • The String() method.
  • Place your tests in an appropriate file (for example, in internal/parser/version_test.go) to ensure any updates to these methods are properly covered.
  • Verify that any new test not only compiles but also properly asserts the expected behavior of these methods.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 16-16: internal/parser/version.go#L16
Added line #L16 was not covered by tests


[warning] 18-19: internal/parser/version.go#L18-L19
Added lines #L18 - L19 were not covered by tests

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/analysis/version_check.go (1)

72-119: Consider adding a return statement after pushing diagnostic for experimental features.

The function correctly handles version mismatch cases by returning after pushing diagnostics, but doesn't return after pushing diagnostics for missing feature flags. This creates inconsistent behavior where a program could fail both version checks and feature flag checks, but only see the version error.

 if !flagEnabled {
 	res.pushDiagnostic(rng, ExperimentalFeature{
 		Name: clause.FeatureFlag,
 	})
+	return
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c601a68 and 2a22d35.

📒 Files selected for processing (3)
  • internal/analysis/check.go (7 hunks)
  • internal/analysis/check_test.go (2 hunks)
  • internal/analysis/version_check.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/analysis/check.go
🧰 Additional context used
🧬 Code Definitions (1)
internal/analysis/check_test.go (6)
internal/parser/antlrParser/numscript_parser.go (16) (16)
  • t (375-375)
  • t (782-782)
  • t (844-844)
  • t (962-962)
  • t (1037-1037)
  • t (1095-1095)
  • t (1570-1570)
  • t (1747-1747)
  • t (1902-1902)
  • t (2046-2046)
  • t (2221-2221)
  • t (2378-2378)
  • t (2415-2415)
  • t (2589-2589)
  • t (2782-2782)
  • t (2977-2977)
internal/analysis/check.go (1) (1)
  • Diagnostic (88-92)
internal/parser/range.go (2) (2)
  • Range (13-16)
  • RangeOfIndexed (155-164)
internal/analysis/diagnostic_kind.go (4) (4)
  • VersionMismatch (276-279)
  • VersionMismatch (285-287)
  • ExperimentalFeature (289-291)
  • ExperimentalFeature (297-299)
internal/parser/version.go (2) (2)
  • VersionMachine (14-14)
  • NewVersionInterpreter (28-34)
internal/interpreter/interpreter_error.go (1) (1)
  • ExperimentalFeature (197-200)
🔇 Additional comments (12)
internal/analysis/version_check.go (5)

11-23: Looks good - implementation for version checking on infix operations.

The function correctly identifies when a binary infix operation uses non-literal values and enforces version 0.0.15 as a requirement. This ensures backward compatibility while supporting newer syntax.


25-32: Clear implementation of oneof feature version check.

This function appropriately requires both version 0.0.15 and the experimental oneof feature flag, ensuring that experimental features are properly gated behind version requirements and feature flags.


34-45: Appropriate validation for overdraft function versioning.

The function correctly checks if the function call is specifically for "origin_overdraft" before enforcing version and feature flag requirements. This ensures that only relevant function calls are subject to version checks.


47-63: Good implementation of account interpolation version check.

The function efficiently uses slices.ContainsFunc to detect variable interpolation in account names, and only enforces version requirements when actual interpolation is present. The early return for non-interpolated accounts is a nice optimization.


67-70: Well-structured version requirement clause.

The VersionClause struct cleanly encapsulates both version requirements and optional feature flags in a reusable component.

internal/analysis/check_test.go (7)

676-698: Good test for ensuring version checks are skipped when no version is specified.

This test verifies the system's default behavior of not enforcing version constraints when no version directive is present in the source code.


700-731: Comprehensive test for version mismatch with machine version.

This test properly verifies that using non-literal division with the "machine" version produces the correct version mismatch diagnostic.


733-765: Thorough test for version compatibility checking.

This test confirms that the system correctly identifies when a program is using a version (0.0.1) that's too old for a feature requiring version 0.0.15.


767-791: Good test for experimental feature flag requirements.

The test correctly verifies that using the "oneof" feature without enabling the corresponding feature flag produces the appropriate diagnostic, even when the version requirement is met.


793-810: Well-structured test for feature flag enablement.

This test confirms that the system allows the "oneof" feature when both the version requirement is met and the feature flag is enabled.


812-838: Effective test for account interpolation feature flag requirements.

The test properly verifies that using account interpolation with variables requires the experimental feature flag to be enabled.


840-863: Good test coverage for overdraft function versioning.

This test ensures that using the overdraft function requires the appropriate feature flag, maintaining consistency with the implementation in version_check.go.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant