pipe/test/fixtures/stuck_loading/lib/freezed_style.dart
trvon 6e2d47f7db
fix(state-flow): credit freezed factory calls to their redirect target
freezed declares variants as redirecting factories on the base
(`const factory DocState.loading() = DocLoading;`) and blocs emit through
them. `emit(const DocState.loading())` was recorded as emitting
`DocState`, which is never a variant, so no freezed emission matched and
every variant the UI renders was reported by rendered-not-emitted as a
dead branch.

Factory redirects are now also kept by constructor name, and an instance
creation of `Type.ctor` (or an unnamed redirecting factory) is credited to
the class it redirects to, for emissions, `state =` assignments and
dispatches alike.

Reproduced on freezed_style.dart before the fix: DocLoading, DocReady
and DocStale all reported as never emitted; after, only DocStale, which
really is never emitted and stays as the positive control. No change on
nuwayze, tick, dex or word_alive.
2026-09-22 13:39:31 -06:00

41 lines
1.2 KiB
Dart

import 'bloc.dart';
// --- a freezed-style union --------------------------------------------------
//
// freezed declares variants as redirecting factories on the base, and the bloc
// emits through them: `emit(const DocState.loading())` builds a DocLoading.
// Recording the base type (`DocState`) meant no emission ever matched a variant,
// so every variant the UI renders was reported as never emitted. The variant
// classes are written by hand here, as the generated file would declare them,
// because this fixture has no dependencies and no codegen.
class DocEvent {}
sealed class DocState {
const DocState();
const factory DocState.loading() = DocLoading;
const factory DocState.ready() = DocReady;
/// Declared, rendered, and never emitted: the positive control that proves
/// redirect resolution did not simply suppress the rule.
const factory DocState.stale() = DocStale;
}
class DocLoading extends DocState {
const DocLoading();
}
class DocReady extends DocState {
const DocReady();
}
class DocStale extends DocState {
const DocStale();
}
class DocBloc extends Bloc<DocEvent, DocState> {
DocBloc() : super(const DocState.loading());
void load() => emit(const DocState.ready());
}