# Hydrogene yields stale local values in switch expressions

**URL:** https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255
**Category:** C#
**Created:** [November 1, 2026, 5:51am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255 "2026-11-01T05:51:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![chikega](https://talk.remobjects.com/user_avatar/talk.remobjects.com/chikega/32/15211_2.png) [@chikega](https://talk.remobjects.com/u/chikega)
#### Post date: [November 1, 2026, 5:51am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/1 "2026-11-01T05:51:31Z")

</div>

Hi Marc _et al_,

I found what looks like a Hydrogene compiler issue involving a local declared first and assigned afterward. The local has the correct value when printed, but a C# switch expression appears to use its original default value instead.

Minimal repro:

```auto
using System;

int number;
number = 2;

var result = number switch
{
    0 => "Zero",
    1 => "One",
    2 => "Two",
    3 => "Three",
    _ => "Other",
};

writeLn($"number = {number}, result = {result}");

```

Expected:

```auto
number = 2, result = Two

```

Actual with Hydrogene 13.0.0.3141, in both Debug and Release:

```auto
number = 2, result = Zero

```

The equivalent code works when the variable is initialized as part of its declaration:

```auto
var number = 2;

```

A traditional `switch`/`case` statement also produces the expected result. I also ran the same minimal source under Roslyn in Debug and Release, where it produces the expected output.

I used GenAI to help organize the investigation and produce the attached **`Hydrogene-Stale-Local-Bug-Report.md`**. It includes the narrowing process, additional reduced repros, Debug/Release results, and the separate Roslyn control evidence. I reviewed the results and repros, but wanted to provide the fuller document in case it makes diagnosis easier.

Thanks!  
[Hydrogene-Stale-Local-Bug-Report.pdf](https://talk.remobjects.com/uploads/short-url/5KWRt6B1SwvVZWgMdkVoh0ccIpP.pdf) (96.1 KB)

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 2, 2026, 7:30am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/2 "2026-11-02T07:30:02Z")

</div>

Logged as [bugs://E27963](https://www.remobjects.com/portal/bugs/?id=E27963).

---

<div class="post-metadata">

### Author: ![chikega](https://talk.remobjects.com/user_avatar/talk.remobjects.com/chikega/32/15211_2.png) [@chikega](https://talk.remobjects.com/u/chikega)
#### Post date: [November 3, 2026, 2:29am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/3 "2026-11-03T02:29:35Z")

</div>

I tested the equivalent in Oxygene and it passes the test. So, it has been determined that Oxygene is not stale 😆

```oxygene

namespace OxygeneStaleSwitch;

  begin
    var number1: Integer;
    if Integer.TryParse('1', out number1) then begin
      var description1 := case number1 of
        1: 'One'; // 'One'
        2: 'Two';
        else 'Other';
      end;
    
      writeLn(description1);
      
      //==================//
      var number2: Integer;

      if Integer.TryParse('2', out number2) then begin
        var copy := number2;

        var description2 := case number2 of
          2: 'Two';
          else 'Other';
        end;

        writeLn(copy); // 2
        writeLn(description2); // 'Two'
  end;

end.

```

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [November 3, 2026, 10:28am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/4 "2026-11-03T10:28:31Z")

</div>

Yeah, this is C#-only, all platform. already fixed internally, awaiting final test & merge approval. Sorry for neglecting to provide an updated status.

---

<div class="post-metadata">

### Author: ![chikega](https://talk.remobjects.com/user_avatar/talk.remobjects.com/chikega/32/15211_2.png) [@chikega](https://talk.remobjects.com/u/chikega)
#### Post date: [November 4, 2026, 12:16am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/5 "2026-11-04T00:16:48Z")

</div>

No worries Marc - I’m just glad to be of help 🤠

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [November 4, 2026, 10:54am UTC](https://talk.remobjects.com/t/hydrogene-yields-stale-local-values-in-switch-expressions/34255/6 "2026-11-04T10:54:32Z")

</div>

much appreciated!
