mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.4k stars 310 forks source link

MobxCodegen - RangeError #821

Closed phcs971 closed 2 years ago

phcs971 commented 2 years ago

I'm getting an error when running

flutter packages pub run build_runner watch --delete-conflicting-outputs

It also happens on build_runner build and if I remove the --delete-conflicting-outputs

[SEVERE] mobx_codegen:mobx_generator on lib/app/enums/marital_status_enum.dart:

RangeError (index): Invalid value: Valid value range is empty: 0
#0      List.[] (dart:core-patch/growable_array.dart:264:36)
#1      ElementWalker.getConstructor (package:analyzer/src/generated/declaration_resolver.dart:159:21)
#2      ResolutionVisitor.visitConstructorDeclaration (package:analyzer/src/dart/resolver/resolution_visitor.dart:283:54)
#3      ConstructorDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:2512:15)
#4      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7813:20)
#5      ResolutionVisitor.visitEnumDeclaration.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:415:22)
#6      ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1413:8)
#7      ResolutionVisitor.visitEnumDeclaration.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:408:7)
#8      ResolutionVisitor._withElementWalker (package:analyzer/src/dart/resolver/resolution_visitor.dart:1402:8)
#9      ResolutionVisitor.visitEnumDeclaration (package:analyzer/src/dart/resolver/resolution_visitor.dart:407:5)
#10     EnumDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:3405:50)
#11     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7813:20)
#12     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2105:21)
#13     RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:765:10)
#14     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2098:50)
#15     LibraryAnalyzer._resolveFile (package:analyzer/src/dart/analysis/library_analyzer.dart:752:10)
#16     LibraryAnalyzer._parseAndResolve.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:597:7)
#17     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:614:13)
#18     LibraryAnalyzer._parseAndResolve (package:analyzer/src/dart/analysis/library_analyzer.dart:596:11)
#19     LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:105:17)
#20     AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1447:11)
#21     PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#22     AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1424:20)
#23     AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1485:26)
#24     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1097:20)
#25     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2127:24)
<asynchronous suspension>

The file it reports contained the following code:

enum MaritalStatus {
  Single("União Estável"),
  Married("Divorciado(a)"),
  Widowed("Casado(a)"),
  Divorced("Solteiro(a)"),
  CommonLawMarriage("Viúvo(a)");

  final String text;

  const MaritalStatus(this.text);
}

Once it started happening right around when I started using enhanced enums, I tried downgrading it to normal enums (which worked with the build_runner for more than a year), but the error persisted.

Current content:

enum MaritalStatus { Single, Married, Widowed, Divorced, CommonLawMarriage }

extension MaritalStatusExtension on MaritalStatus {
  String get text {
    switch (this) {
      case MaritalStatus.CommonLawMarriage:
        return "União Estável";
      case MaritalStatus.Divorced:
        return "Divorciado(a)";
      case MaritalStatus.Married:
        return "Casado(a)";
      case MaritalStatus.Single:
        return "Solteiro(a)";
      case MaritalStatus.Widowed:
        return "Viúvo(a)";
    }
  }
}

After the [SEVERE] report it goes on a loop like the following:

[INFO] 23.1s elapsed, 12/28 actions completed.
[INFO] 24.2s elapsed, 12/28 actions completed.
[INFO] 25.2s elapsed, 12/28 actions completed.
[INFO] 26.3s elapsed, 12/28 actions completed.
[WARNING] No actions completed for 15.0s, waiting on:
  - mobx_codegen:mobx_generator on lib/app/enums/invoice_status_enum.dart
  - mobx_codegen:mobx_generator on lib/app/enums/social_network_enum.dart
  - mobx_codegen:mobx_generator on lib/app/enums/status_enum.dart
  - mobx_codegen:mobx_generator on lib/app/enums/credit_cart_type_enum.dart
  - mobx_codegen:mobx_generator on lib/app/app_widget.dart
  .. and 11 more

[INFO] 28.1s elapsed, 12/28 actions completed.
[INFO] 29.1s elapsed, 12/28 actions completed.
phcs971 commented 2 years ago

flutter doctor --verbose

[✓] Flutter (Channel stable, 3.0.1, on macOS 12.3.1 21E258 darwin-x64, locale pt-BR)
    • Flutter version 3.0.1 at /Users/phcs/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (6 days ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/phcs/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.67.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

dart --version

Dart SDK version: 2.17.1 (stable) (Tue May 17 17:58:21 2022 +0000) on "macos_x64"

pubspec.yaml (environment and dependencies)


environment:
  sdk: ">=2.17.0 <3.0.0"

dependencies:
  app_tracking_transparency: ^2.0.2+4
  brasil_fields: ^1.4.4
  cached_network_image: ^3.2.1
  camera: ^0.9.5+1
  carousel_slider: ^4.1.1
  collection: ^1.15.0
  connectivity_plus: ^2.3.0
  country_picker: ^2.0.15
  cupertino_icons: ^1.0.4
  device_info_plus: ^3.2.3
  dio: ^4.0.6
  dotted_line: ^3.1.0
  extended_masked_text: ^2.3.1
  facebook_app_events: ^0.16.0
  firebase_analytics: ^9.1.8
  firebase_core: ^1.17.0
  firebase_dynamic_links: ^4.2.3
  firebase_performance: ^0.8.0+12
  firebase_remote_config: ^2.0.7
  flutter:
    sdk: flutter
  flutter_animator: ^3.2.1
  flutter_appauth:
    git:
      url: https://github.com/guykogus/flutter_appauth.git
      path: flutter_appauth
      ref: fix-auth-service
  flutter_icons:
    git:
      url: https://github.com/adarsh-technocrat/flutter-icons
  flutter_localizations:
    sdk: flutter
  flutter_mobx: ^2.0.6+1
  flutter_modular: ^5.0.2
  flutter_secure_storage: ^5.0.2
  flutter_segment: ^3.7.0
  flutter_siri_suggestions: ^2.1.0
  flutter_svg: ^1.0.3
  flutter_typeahead: ^4.0.0
  flutter_widget_from_html: ^0.8.5
  get_mac:
    git:
      url: https://gitlab.com/phcs971/get-mac-plugin.git
  google_fonts: ^3.0.1
  hive: ^2.2.0
  hive_flutter: ^1.1.0
  http: ^0.13.4
  image_cropper: ^2.0.3
  image_picker: ^0.8.5+3
  in_app_review: ^2.0.4
  intl: ^0.17.0
  location: ^4.4.0
  logger: ^1.1.0
  lottie: ^1.3.0
  map_launcher: ^2.2.2
  mime: ^1.0.2
  mobx: ^2.0.7+2
  modular_interfaces: ^2.0.1
  network_info_plus: ^2.1.3
  onesignal_flutter: ^3.3.0
  package_info_plus: ^1.4.2
  path: ^1.8.0
  path_provider: ^2.0.10
  permission_handler: ^9.2.0
  pin_code_fields: ^7.4.0
  pull_to_refresh: ^2.0.0
  qr_code_scanner: ^0.7.0
  qr_flutter: ^4.0.0
  search_cep: ^4.0.0+1
  sentry_flutter: ^6.5.1
  shake: ^2.1.0
  share: ^2.0.4
  shimmer: ^2.0.0
  tutorial_coach_mark: ^1.2.3
  url_launcher: ^6.1.2
  uuid: ^3.0.6
  validators: ^3.0.0
  webview_flutter: ^3.0.4
  wifi_iot: ^0.3.16
  youtube_player_flutter: ^8.1.0

dev_dependencies:
  build_runner: ^2.1.11
  dart_code_metrics: ^4.15.2
  flutter_launcher_icons: ^0.9.2
  flutter_lints: ^2.0.1
  flutter_test:
    sdk: flutter
  http_mock_adapter: ^0.3.2
  mobx_codegen: ^2.0.7
  mockito: ^5.1.0
  modular_test: ^2.0.0

dependency_overrides:
  pull_to_refresh: #Flutter 3.0.0
    git:
      url: https://github.com/miquelbeltran/flutter_pulltorefresh
      ref: master
  qr_code_scanner: #Flutter 3.0.0
    git:
      url: https://github.com/X-SLAYER/qr_code_scanner.git
      ref: flutter-beta
phcs971 commented 2 years ago

Solved in https://github.com/dart-lang/build/issues/3310