Repository: flutter
Issue: [Flutter Web] yield switch construct aborts the application in debug mode
Labels: framework,a: debugging,platform-web,has reproducible steps,team-web,found in release: 3.27,found in release: 3.28

### Steps to reproduce

1. Install flutter version 3.27.1 
2. Create an empty project 
3. Add the code from the example 
4. Run in debug mode

### Expected results

The app works

### Actual results

The application hangs on loading and does not show anything

### Code sample

The example also has a working variant (commented function “test”).

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

abstract interface class HttpException implements Exception {
  const HttpException();
}

class HttpMessageError implements HttpException {
  HttpMessageError({
    required this.statusCode,
  });

  final int? statusCode;
}

sealed class NameException implements Exception {}

class NameAlreadyExistsException implements NameException {
  const NameAlreadyExistsException(this.parent);

  final Object parent;
}

class SaveException implements Exception {
  const SaveException(this.parent);

  final Object parent;
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // Not working
  Stream<Exception> test() async* {
    try {
      throw HttpMessageError(statusCode: 500);
    } catch (e) {
      yield switch (e) {
        HttpMessageError(statusCode: final statusCode) when statusCode == 400 =>
          NameAlreadyExistsException(e),
        HttpMessageError(statusCode: final statusCode) when statusCode == 409 =>
          NameAlreadyExistsException(e),
        final e => SaveException(e),
      };
    }
  }

  // Working
  // Stream<Exception> test() async* {
  //   try {
  //     throw HttpMessageError(statusCode: 500);
  //   } catch (e) {
  //     if (e case HttpMessageError(statusCode: final statusCode)
  //         when statusCode == 400) {
  //       yield NameAlreadyExistsException(e);
  //     } else if (e case HttpMessageError(statusCode: final statusCode)
  //         when statusCode == 409) {
  //       yield NameAlreadyExistsException(e);
  //     } else {
  //       yield SaveException(e);
  //     }
  //   }
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            StreamBuilder(
              stream: test(),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return Text(snapshot.data?.toString() ?? '');
                }
                return const CircularProgressIndicator();
              },
            ),
          ],
        ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

<img width="565" alt="2025-01-13" src="https://github.com/user-attachments/assets/a714bbe3-b71a-4fd3-a346-21d75b8d1ff8" />


</details>


### Logs

<details open><summary>Logs</summary>

```console
Uncaught SyntaxError: Identifier 'statusCode' has already been declared

Uncaught TypeError: Cannot read properties of undefined (reading 'main')
    at load__web_entrypoint_dart (web_entrypoint.dart.lib.js:14:60)
    at Object.execCb (require.js:1696:33)
    at Module.check (require.js:883:51)
    at Module.<anonymous> (require.js:1139:34)
    at require.js:134:23
    at require.js:1189:21
    at each (require.js:59:31)
    at Module.emit (require.js:1188:17)
    at Module.check (require.js:938:30)
    at Module.<anonymous> (require.js:1139:34)
    at require.js:134:23
    at require.js:1189:21
    at each (require.js:59:31)
    at Module.emit (require.js:1188:17)
    at Module.check (require.js:938:30)
    at Module.enable (require.js:1176:22)
    at Module.init (require.js:788:26)
    at callGetModule (require.js:1203:63)
    at Object.completeLoad (require.js:1590:21)
    at HTMLScriptElement.onScriptLoad (require.js:1717:29)
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.27.1, on macOS 14.2.1 23C71 darwin-arm64, locale ru-RU)
    • Flutter version 3.27.1 on channel stable at /Users/itmiftah10/SDK/flutter/versions/3.27.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (4 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/itmiftah10/SDK/android_studio
    • Platform android-34, build-tools 33.0.2
    • ANDROID_HOME = /Users/itmiftah10/SDK/android_studio
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (1 available)
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.70

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>