Repository: flutter
Issue: Nested generic function inside factory constructor crashes flutter run (web) compiler
Labels: c: regression,tool,dependency: dart,platform-web,has reproducible steps,P1,team-tool,triaged-tool,dependency:dart-triaged,found in release: 3.27,found in release: 3.28

### Steps to reproduce

1. Update to flutter 3.27.0
2. `flutter run -d chrome`

### Expected results

Chrome opens with the flutter application running

### Actual results

Dart compiler crashes. Note that this does not happen for other non-web runs (eg windows). This also does not happen when compiling a js bundle from it

### Code sample

<details open><summary>Code sample</summary>

Due to the confidential nature and the lack of any indication in which file the bug is triggered, we cannot provide a code sample to reproduce this. If we somehow can get even more verbose logs that point us to which function is being compiled that crashes the compiler, we may be able to extract a code sample.

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
Launching lib\main.dart on Chrome in debug mode...
Unhandled exception:
Exception: RtiTypeEnvironments should not receive extended type parameters.
#0      RtiTypeEnvironment.extend (package:dev_compiler/src/kernel/type_environment.dart:137)
#1      ProgramCompiler._emitFunction (package:dev_compiler/src/kernel/compiler.dart:3590)
#2      ProgramCompiler.visitFunctionDeclaration (package:dev_compiler/src/kernel/compiler.dart:4882)
#3      FunctionDeclaration.accept (package:kernel/src/ast/statements.dart:1747)
#4      ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3971)
#5      MappedIterable.elementAt (dart:_internal/iterable.dart:395)
#6      ListIterator.moveNext (dart:_internal/iterable.dart:364)
#7      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189)
#8      new _GrowableList.of (dart:core-patch/growable_array.dart:150)
#9      new List.of (dart:core-patch/array_patch.dart:39)
#10     SetBase.toList (dart:collection/set.dart:119)
#11     ProgramCompiler.visitBlock (package:dev_compiler/src/kernel/compiler.dart:4160)
#12     Block.accept (package:kernel/src/ast/statements.dart:103)
#13     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3971)
#14     ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:4004)
#15     ProgramCompiler._emitFactoryConstructor.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:2460)
#16     ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2749)
#17     ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3749)
#18     ProgramCompiler._emitFactoryConstructor (package:dev_compiler/src/kernel/compiler.dart:2458)
#19     ProgramCompiler._emitClassMethods (package:dev_compiler/src/kernel/compiler.dart:2230)
#20     ProgramCompiler._emitClassDeclaration (package:dev_compiler/src/kernel/compiler.dart:1041)
#21     ProgramCompiler._emitClass (package:dev_compiler/src/kernel/compiler.dart:973)
#22     List.forEach (dart:core-patch/growable_array.dart:417)
#23     ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:912)
#24     List.forEach (dart:core-patch/growable_array.dart:417)
#25     ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:620)
#26     IncrementalJavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:231)
#27     FrontendCompiler.writeJavaScriptBundle (package:frontend_server/frontend_server.dart:874)
<asynchronous suspension>
#28     FrontendCompiler.compile (package:frontend_server/frontend_server.dart:690)
<asynchronous suspension>
#29     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1392)
<asynchronous suspension>
the Dart compiler exited unexpectedly.
Waiting for connection from debug service on Chrome...             14.7s
Failed to compile application.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.27.0, on Microsoft Windows [Version 10.0.22631.4602], locale en-GB)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/windows-android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.3)
[!] Android Studio (not installed)
[√] IntelliJ IDEA Ultimate Edition (version 2024.3)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 2 categories.
```

</details>