Skip to content

Add variable definition "def" in switch#360

Merged
atkin-mc merged 26 commits intomainfrom
atkin-grpc-federation-def
Feb 24, 2026
Merged

Add variable definition "def" in switch#360
atkin-mc merged 26 commits intomainfrom
atkin-grpc-federation-def

Conversation

@atkin-mc
Copy link
Collaborator

@atkin-mc atkin-mc commented Feb 10, 2026

Add local variable definition to the message.switch statement. This follows the same rules of scoping as message.validation.error (i.e., all variables are in the same namespace regardless of scope, so it is not possible to introduce a duplicate variable name in a child scope). Variable definitions for a switch case are only evaluated when the if for the case evaluates to true.

This PR also adds test cases for switch to source/file_test.go and adds some functionality to source/file.go that was left out of #356

Also, docs/reference.md doesn't mention message.validation.error.def, message.validation.error.details.def, this PR documents those fields.

@github-actions

This comment has been minimized.

@atkin-mc atkin-mc changed the title DRAFT: def in switch Add variable definition "def" in switch Feb 18, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link

Code Metrics Report

main (6ce0d51) #360 (bcffbf4) +/-
Coverage 67.6% 67.9% +0.2%
Code to Test Ratio 1:0.4 1:0.4 +0.0
Test Execution Time 7m9s 7m10s +1s
Details
  |                     | main (6ce0d51) | #360 (bcffbf4) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          67.6% |          67.9% | +0.2% |
  |   Files             |             84 |             84 |     0 |
  |   Lines             |          15424 |          15582 |  +158 |
+ |   Covered           |          10440 |          10587 |  +147 |
+ | Code to Test Ratio  |          1:0.4 |          1:0.4 |  +0.0 |
  |   Code              |          47935 |          48318 |  +383 |
+ |   Test              |          20190 |          20407 |  +217 |
- | Test Execution Time |           7m9s |          7m10s |   +1s |

Code coverage of files in pull request scope (75.3% → 75.6%)

Files Coverage +/- Status
generator/code_generator.go 78.0% +0.1% modified
grpc/federation/cel.go 0.0% 0.0% modified
grpc/federation/generator/decode.go 67.5% -0.1% modified
grpc/federation/generator/encode.go 77.1% 0.0% modified
internal/testutil/builder.go 84.9% +0.2% modified
resolver/def.go 91.7% -1.8% modified
resolver/format.go 89.9% +0.1% modified
resolver/message.go 73.5% +0.0% modified
resolver/resolver.go 82.7% -0.2% modified
resolver/types.go 87.5% 0.0% modified
source/clone.go 83.3% 0.0% modified
source/file.go 78.9% +1.6% modified
source/location.go 0.0% 0.0% modified
source/location_builder.go 77.8% +0.3% modified

Reported by octocov

@atkin-mc atkin-mc requested a review from goccy February 18, 2026 02:29
Copy link
Member

@goccy goccy left a comment

Choose a reason for hiding this comment

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

Awesome !!! LGTM 👍

@atkin-mc atkin-mc merged commit 5eeb102 into main Feb 24, 2026
4 checks passed
@atkin-mc atkin-mc deleted the atkin-grpc-federation-def branch February 24, 2026 07:32
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