Skip to content

[pigeon] Enhanced enums fields are coalesced into the next class #160827

Description

@Levi-Lesches

What package does this bug report belong to?

pigeon

What target platforms are you seeing this bug on?

Windows

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
  pigeon:
    dependency: "direct dev"
    description:
      name: pigeon
      sha256: "6c318e3ef13f52db30ab85ef45b4746ba33b837aeecc549eb8578f78a3dde19a"
      url: "https://pub.dev"
    source: hosted
    version: "22.7.0"

Steps to reproduce

  1. Run dart pub add --dev pigeon
  2. Ensure that you get Pigeon version 22.7.0
  3. Save the attached Code Sample file to pigeon/temp.dart
  4. Run dart run pigeon --input pigeon/temp.dart
  5. Observe analysis errors

Expected results

Since the Pigeon file has an enhanced enum with fields, the Dart output should as well. In other words:

enum MyEnum {
  a(1),
  b(2);

  const MyEnum(this.myEnumValue)
  final int myEnumValue; 
}

class MyMessage1 {
  MyMessage1({
    this.field1,
  });

  int? field1;
  // ...
}

class MyMessage2 {
  MyMessage2({
    this.field2,
  });

  int? field2;
  // ...
}

Actual results

Pigeon merges the enhanced enum's field with the preceding class. This is doubly bad if there are two enums with the same named field, as that will cause duplicate field errors in the class.

enum MyEnum {
  a,
  b,

  // missing myEnumValue
}

class MyMessage1 {
  MyMessage1({
    this.field1,
    required this.myEnumValue,
  });

  int? field1;

  int myEnumValue;  // <-- This shouldn't be here!

  // ...
}

class MyMessage2 {
  MyMessage2({
    this.field2,
  });

  int? field2;

  // ...
}

Code sample

Code sample
// pigeon/temp.dart
@ConfigurePigeon(PigeonOptions(
  dartOut: 'pigeon/temp.g.dart',
  dartOptions: DartOptions(),
))
library;

import 'package:pigeon/pigeon.dart';

class MyMessage1 {
  int? field1;
}

enum MyEnum {
  a(1),
  b(2);

  final int myEnumValue;
  const MyEnum(this.myEnumValue);
}

class MyMessage2 {
  int? field2;
}

Screenshots or Videos (None)

Screenshots / Video demonstration

[Upload media here]

Logs (None)

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.0, on Microsoft Windows [Version 10.0.26100.2605], locale en-US)
    • Flutter version 3.27.0 on channel stable at C:\Users\Levi\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8495dee1fd (2 weeks ago), 2024-12-10 14:23:39 -0800
    • Engine revision 83bacfc525
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\Levi\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.7.1)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.7.34009.444
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.10+0--11572160)

[✓] VS Code, 64-bit edition (version 1.95.3)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.102.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.2605]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 131.0.6778.140
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 131.0.2903.112

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions