Skip to content

fix: replace duplicate typeof(long) with typeof(ushort) in BaseSerializer.GetSize(T)#8714

Open
Evangelink wants to merge 2 commits into
mainfrom
fix/getsize-duplicate-long-case-02ebf431210518ba
Open

fix: replace duplicate typeof(long) with typeof(ushort) in BaseSerializer.GetSize(T)#8714
Evangelink wants to merge 2 commits into
mainfrom
fix/getsize-duplicate-long-case-02ebf431210518ba

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Summary

The GetSize<T>() switch expression in BaseSerializer had a duplicate typeof(long) arm that was unreachable dead code. The second arm should be typeof(ushort) to properly cover all the numeric types used in the IPC serializers.

Before:

private static int GetSize<T>() => typeof(T) switch
{
    Type type when type == typeof(int) => sizeof(int),
    Type type when type == typeof(long) => sizeof(long),
    Type type when type == typeof(short) => sizeof(short),
    Type type when type == typeof(bool) => sizeof(bool),
    Type type when type == typeof(byte) => sizeof(byte),
    Type type when type == typeof(long) => sizeof(long),  // ← duplicate, unreachable
    _ => 0,
};

After:

private static int GetSize<T>() => typeof(T) switch
{
    Type type when type == typeof(int) => sizeof(int),
    Type type when type == typeof(long) => sizeof(long),
    Type type when type == typeof(short) => sizeof(short),
    Type type when type == typeof(ushort) => sizeof(ushort),
    Type type when type == typeof(bool) => sizeof(bool),
    Type type when type == typeof(byte) => sizeof(byte),
    _ => 0,
};

No behavioral change — WriteSize<ushort> is not currently called, so this fix adds completeness while removing dead code.

Generated by Adhoc QA · sonnet46 3.2M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/adhoc-qa.md@main

… switch

The GetSize<T> switch expression had an unreachable duplicate arm for
typeof(long). The second arm should be typeof(ushort) to properly
cover the ushort type in the switch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 31, 2026 07:08
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/qa Created by the adhoc-qa agentic workflow. labels May 31, 2026
Copy link
Copy Markdown
Contributor

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 fixes a dead switch arm in BaseSerializer.GetSize<T>() by replacing the duplicate typeof(long) case with typeof(ushort), aligning size calculation coverage with the serializer’s ushort read/write helpers.

Changes:

  • Adds ushort size handling in GetSize<T>().
  • Removes the unreachable duplicate long switch arm.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/IPC/Serializers/BaseSerializer.cs Updates primitive size mapping used by IPC serialization helpers.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Type type when type == typeof(bool) => sizeof(bool),
Type type when type == typeof(byte) => sizeof(byte),
Type type when type == typeof(long) => sizeof(long),
_ => 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this throw unreachable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch — fixed in 6e4ca9b. Replaced _ => 0, with _ => throw ApplicationStateGuard.Unreachable(), to make the invariant explicit (GetSize<T> is private and only called by WriteSize<T> with a known closed set of primitive types).

@Evangelink Evangelink marked this pull request as ready for review May 31, 2026 18:16
Addresses review feedback from @Youssef1313: the default arm should throw to make the invariant explicit, since GetSize<T> is private and only invoked from WriteSize<T> with a fixed set of supported primitive types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/automation Created or maintained by an agentic workflow. type/qa Created by the adhoc-qa agentic workflow.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants