Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mobx_codegen] error with code generation when file has unnamed extension #1010

Closed
HosamHasanRamadan opened this issue Jul 17, 2024 · 2 comments · Fixed by #1020
Closed

[mobx_codegen] error with code generation when file has unnamed extension #1010

HosamHasanRamadan opened this issue Jul 17, 2024 · 2 comments · Fixed by #1020
Assignees
Labels
bug Something isn't working

Comments

@HosamHasanRamadan
Copy link

Reproducable code

import 'package:mobx/mobx.dart';

part 'view_model.g.dart';

class ViewModel = _ViewModel with _$ViewModel;

abstract class _ViewModel with Store {
  @observable
  List<int> list = [];
}

extension on int {}

Error

[INFO] Starting Build
[INFO] Updating asset graph completed, took 1ms
[SEVERE] mobx_codegen:mobx_generator on lib/view_model.dart:

Null check operator used on a null value
package:mobx_codegen/src/type_names.dart 32:46            LibraryScopedNameFinder.namesByElement
package:mobx_codegen/src/type_names.dart 137:12           LibraryScopedNameFinder._getNamedElementTypeName
package:mobx_codegen/src/type_names.dart 94:12            LibraryScopedNameFinder._getDartTypeName
dart:_internal                                            ListIterable.toList
package:mobx_codegen/src/type_names.dart 133:56           LibraryScopedNameFinder._getNamedElementTypeName
package:mobx_codegen/src/type_names.dart 94:12            LibraryScopedNameFinder._getDartTypeName
package:mobx_codegen/src/type_names.dart 48:7             LibraryScopedNameFinder.findVariableTypeName
package:mobx_codegen/src/store_class_visitor.dart 100:28  StoreClassVisitor.visitFieldElement
package:analyzer/src/dart/element/element.dart 3110:54    FieldElementImpl.accept
package:analyzer/src/dart/element/element.dart 2491:13    ElementImpl.visitChildren
package:mobx_codegen/src/mobx_codegen_base.dart 85:9      StoreGenerator._generateCodeFromTemplate
package:mobx_codegen/src/mobx_codegen_base.dart 67:13     StoreGenerator._generateCodeForMixinStore
dart:core                                                 Iterable.toSet
package:mobx_codegen/src/mobx_codegen_base.dart 26:68     StoreGenerator.generate
package:source_gen/src/builder.dart 342:33                _generate
dart:async                                                Stream.toList.<fn>
package:source_gen/src/builder.dart 107:9                 _Builder._generateForLibrary
package:source_gen/src/builder.dart 99:5                  _Builder.build

[INFO] Running build completed, took 47ms
[INFO] Caching finalized dependency graph completed, took 23ms
[SEVERE] Failed after 74ms

Packages

build_runner: ^2.4.11
mobx_codegen: ^2.6.1
flutter_mobx: ^2.2.1+1
mobx: ^2.3.3+2

Flutter version:
3.22.2
if I add name to extension, it will work fine

extension _intX on int {}
@princebansal
Copy link

Omg. This is such a life saver. I tried all my luck but couldn't get through the build runner. Thanks

@FMorschel
Copy link

This is also a problem with extension type since it does expect on and a name.

@amondnet amondnet self-assigned this Oct 26, 2024
amondnet added a commit to amondnet/mobx.dart that referenced this issue Oct 26, 2024
@amondnet amondnet added the bug Something isn't working label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants