Skip to content

Bump go.mod to 1.23 and remove alias replacements #248

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JacobOaks
Copy link
Contributor

@JacobOaks JacobOaks commented Apr 21, 2025

Alias replacements derived from syntax were introduced in #220 as a way to ensure the aliases used in source code were also used. This helped ensure packages mode worked on go1.22, which didn't have explicit alias node support in the go/types package.

Alias replacements have a couple issues:

Now that go1.24 is released, we can bump go.mod to go1.23, which means we can ensure go/types has an explicit types.Alias node for type aliases, and we can remove the alias replacement logic.

Summary by CodeRabbit

  • New Features
    • Updated support to Go version 1.24.x in testing workflows.
  • Refactor
    • Improved type handling for method signatures, replacing certain type aliases and primitive types with more precise or underlying types in generated mocks.
    • Removed the alias replacement mechanism for type parsing to simplify internal logic.
  • Tests
    • Updated test expectations to align with changes in type handling.
  • Chores
    • Updated Go module files to use Go 1.23.

Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

This update revises the Go version in several go.mod files and the GitHub Actions workflow, moving from Go 1.22 to 1.23 and adding support for Go 1.24 in CI. It removes the alias replacement mechanism from the packageModeParser, simplifying type handling logic. Mock implementations and related tests are updated to use more precise types, replacing type aliases with their underlying types or named types as appropriate. Test expectations are adjusted accordingly to match these type changes, ensuring consistency across the codebase.

Changes

Files/Paths Change Summary
.github/workflows/test.yaml Updated Go version matrix in CI: removed 1.22.x, added 1.24.x.
go.mod
mockgen/internal/tests/generics/go.mod
mockgen/internal/tests/typed/go.mod
tools/go.mod
Updated Go version from 1.22 to 1.23 in module files; no other dependency changes.
mockgen/internal/tests/alias/mock/interfaces.go Changed mock method signatures and function types to use the interface type alias.Fooer instead of the alias type alias.FooerAlias.
mockgen/internal/tests/package_mode/mock/interfaces.go Changed mock method signatures and related function types to use the type alias package_mode.HumansCount instead of the primitive int.
mockgen/package_mode.go Removed alias replacement mechanism from packageModeParser, including associated structs, fields, methods, and logic for handling type aliases. Cleaned up imports accordingly.
mockgen/package_mode_test.go Updated test expectations to use underlying or named types instead of aliases for method parameters and return types in interface tests. No changes to test logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Test Suite

    User->>GitHub Actions: Push code / open PR
    GitHub Actions->>Test Suite: Run tests with Go 1.23.x
    GitHub Actions->>Test Suite: Run tests with Go 1.24.x
    Test Suite-->>GitHub Actions: Report results
    GitHub Actions-->>User: Display test outcomes
Loading
sequenceDiagram
    participant packageModeParser
    participant TypeParser

    packageModeParser->>TypeParser: parseType(t)
    Note right of TypeParser: (Old) Check for alias replacement<br>(New) Directly parse type, no alias lookup
    TypeParser-->>packageModeParser: Return parsed type
Loading

Poem

🐇
A hop from Go 1.22 to 1.24,
Type aliases gone, we mock no more.
Interfaces clear, with names precise,
Our tests now match, isn't that nice?
CI runs fresh, the code feels light—
A rabbit’s leap, everything just right!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6568d88 and 29b9ef2.

📒 Files selected for processing (9)
  • .github/workflows/test.yaml (2 hunks)
  • go.mod (1 hunks)
  • mockgen/internal/tests/alias/mock/interfaces.go (2 hunks)
  • mockgen/internal/tests/generics/go.mod (1 hunks)
  • mockgen/internal/tests/package_mode/mock/interfaces.go (3 hunks)
  • mockgen/internal/tests/typed/go.mod (1 hunks)
  • mockgen/package_mode.go (0 hunks)
  • mockgen/package_mode_test.go (3 hunks)
  • tools/go.mod (1 hunks)
💤 Files with no reviewable changes (1)
  • mockgen/package_mode.go
🧰 Additional context used
🧬 Code Graph Analysis (2)
mockgen/package_mode_test.go (1)
mockgen/model/model.go (4)
  • Type (144-147)
  • NamedType (267-271)
  • Package (30-35)
  • Parameter (129-132)
mockgen/internal/tests/alias/mock/interfaces.go (2)
mockgen/internal/tests/alias/interfaces.go (1)
  • Fooer (10-12)
gomock/call.go (1)
  • Call (25-45)
🔇 Additional comments (17)
tools/go.mod (1)

3-3: Bump Go version for tools module
This updates the minimum required Go version to 1.23 in tools/go.mod, keeping it in sync with the rest of the repository.

go.mod (1)

3-3: Update root module Go version
The root go.mod now specifies Go 1.23, matching the new project-wide minimum Go version.

mockgen/internal/tests/typed/go.mod (1)

3-3: Synchronize typed tests module Go version
The typed tests module is correctly bumped to Go 1.23, aligning with the primary module’s Go version.

mockgen/internal/tests/generics/go.mod (1)

3-3: Align generics tests module Go version
The generics tests module now uses Go 1.23, consistent with the overall version upgrade.

.github/workflows/test.yaml (1)

15-15: Adjust CI matrix for new Go versions
The workflow’s Go version matrix now targets 1.23.x and 1.24.x, removing unsupported 1.22.x. This change is in line with the go.mod updates.

mockgen/package_mode_test.go (5)

317-320: Updated parameter type to match removal of alias replacements

The test expectations now use the named type HumansCount from the package_mode package instead of a primitive int type. This aligns with the PR objective of removing alias replacement logic and relying on Go 1.23+'s native type alias support.


339-342: Consistent type handling for method return values

The HumanPopulation method's return type has been updated to use the named type HumansCount from the package_mode package to maintain consistency with the parameter type changes. This reflects the more precise type representation now available with Go 1.23+'s improved type alias support.


453-453: Using underlying interface type instead of alias

Changed the expected type from FooerAlias to Fooer, properly reflecting the removal of the alias replacement mechanism. This is consistent with the PR objectives to rely on Go's native alias handling rather than custom replacement logic.


459-459: Consistent return type representation

Return type also updated from FooerAlias to Fooer to reflect the more accurate type representation after removing the alias replacement mechanism. This ensures consistent type handling throughout the codebase.


369-371: Removed TODO comment is now implemented

The TODO comment mentioning the need to update this test when bumping Go to 1.23 has been addressed in this PR, as the test now correctly validates the behavior without alias replacement logic.

mockgen/internal/tests/alias/mock/interfaces.go (3)

289-289: Updated parameter type in mock implementation

The Baz method signature has been updated to use alias.Fooer instead of alias.FooerAlias, reflecting the removal of alias replacement logic. This change ensures the mock implementation correctly handles the underlying type.


292-292: Updated type assertion in method implementation

The type assertion for return values has been updated to use alias.Fooer instead of alias.FooerAlias, maintaining consistency with the method signature changes and ensuring correct runtime behavior.


309-309: Consistent type updates in helper methods

The Return, Do, and DoAndReturn methods have all been updated to use alias.Fooer instead of alias.FooerAlias, ensuring consistent type handling throughout the mock implementation. This aligns with the PR objective of using Go's native alias support.

Also applies to: 315-315, 321-321

mockgen/internal/tests/package_mode/mock/interfaces.go (4)

1385-1385: Updated parameter type from primitive to named type

The AddHumans method now uses package_mode.HumansCount instead of int, reflecting the more precise type representation enabled by Go 1.23+'s improved alias support. This change ensures type safety and better API clarity.


1411-1411: Updated function signature in mock callback methods

The Do and DoAndReturn methods now use package_mode.HumansCount instead of int in their function type parameters, ensuring consistent type handling throughout the mock implementation.

Also applies to: 1417-1417


1423-1423: Updated return type and type assertion

The HumanPopulation method now returns package_mode.HumansCount instead of int, and the corresponding type assertion has been updated to maintain consistency with the return type change.

Also applies to: 1426-1426


1443-1443: Consistent type updates in all helper methods

The Return, Do, and DoAndReturn methods for MockEarthHumanPopulationCall have been updated to use package_mode.HumansCount instead of int, ensuring comprehensive and consistent type handling throughout the mock implementation. This aligns with the PR's objective of relying on native type alias support.

Also applies to: 1449-1449, 1455-1455

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

@JacobOaks JacobOaks force-pushed the joaks/go-123 branch 2 times, most recently from a177d86 to 0712b54 Compare April 21, 2025 14:50
Alias replacements derived from syntax were introduced in uber-go#220
as a way to ensure the aliases used in source code were also used.
This helped ensure packages mode worked on go1.22, which didn't have
explicit alias node support in the `go/types` package.

Alias replacements have a couple issues:
* They flat out replace any would-be references to an underlying type
  with an alias type.
* They don't properly handle aliases to generic type instantiations (ref: uber-go#243)

Now that go1.24 is released, we can bump `go.mod` to go1.23,
which means we can ensure `go/types` has an explicit `types.Alias` node
for type aliases, and we can remove the alias replacement logic.
@JacobOaks JacobOaks marked this pull request as ready for review April 21, 2025 14:55
@JacobOaks JacobOaks changed the title Bump go version to 1.23 and remove alias replacements Bump go.mod to 1.23 and remove alias replacements Apr 21, 2025
@JacobOaks JacobOaks requested a review from sywhang April 21, 2025 15:01
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