Skip to content

Dart target: AST coverage for exception types, generated guards, and overload dispatch #175

Description

@danfma

Context

PR #168 landed delegates → `typedef` (Phase 5a). Three more AST features remain before the Dart bridge has the same coverage as the TypeScript bridge:

1. Exception types

C# exception classes (subclasses of `System.Exception`) currently lower to plain Dart classes. Idiomatic Dart wants `class FooException implements Exception` so consumers can `catch (e on FooException)`.

  • Detect `Exception`-derived classes in the IR (or via a semantics flag).
  • Inject `implements Exception` in `IrToDartClassBridge` when the C# base type chain ends in `System.Exception`.
  • Add a regression test.

2. Generated guards (`[GenerateGuard]`)

The TS target emits `isFoo(value: unknown): value is Foo` companion functions for types decorated with `[GenerateGuard]`. The Dart equivalent is a top-level `bool isFoo(dynamic value)` returning `value is Foo`.

  • New `IrToDartGuardBridge` (or extend the class bridge) emitting the guard as a sibling top-level function.
  • Wire it through `DartImportCollector` so consumers can import it.
  • Tests + sample regen.

3. Overload dispatcher

Dart has no method overloading. The TS target lowers C# overloads via a runtime-typecheck dispatcher (`isInt32(args[0])` etc.). For Dart the design has to diverge — likely either:

  • (a) Suffix-based renames: emit `drawInt(int times)` / `drawString(String label)` and surface a diagnostic so callers know to pick the right one. Less ergonomic but mechanical.
  • (b) Single method with optional positional / dynamic dispatch: collapse the overload set to one signature with `dynamic` parameters and runtime branching. Closer to TS shape; loses static typing.

Today `DartTransformer.ReportOverloadDiagnostics` warns and emits only the primary signature — a real fix lives here. Pick a strategy, document the rationale in an ADR, implement.

Dependencies

Part of #28

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions