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

Hot reload does not work when changes include freezed models that embed a nullable realm model #1268

Closed
stevenosse opened this issue May 8, 2023 · 4 comments

Comments

@stevenosse
Copy link

stevenosse commented May 8, 2023

What happened?

I've noticed that when i try to hot reload a page that contains a Realm model, the Dart compiler crashes and i have to run flutter clean to get it work again. This has occured several times, on both windows and macOS.
Other screens/files that does not import a realm model are not affected.

I've also created the associated issue on the Dart repo. Doing it here for tracking purpose: dart-lang/sdk#52312

Flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.7.12, on Microsoft Windows [version 10.0.22621.1555], locale fr-FR)
[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0)
[√] Android Studio (version 2022.2)
[√] IntelliJ IDEA Community Edition (version 2022.3)
[√] VS Code (version 1.78.0)
[√] Connected device (3 available)
[√] HTTP Host Availability

! Doctor found issues in 1 category.

Repro steps

  1. Create a blank flutter project
  2. Import a realm model on any file
  3. Try to run hot reload from that file
  4. Boom : Crash

Version

1.0.3

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

Pixel 7 Pro - Android 13, Xiaomi Mi 10T Pro - Android 11

Code snippets

No response

Stacktrace of the exception/crash you're getting

Unhandled exception:
Crash when compiling:
type 'Block' is not a subtype of type 'ReturnStatement' in type cast

#0      RedirectingFactoryBody.restoreFromDill (package:front_end/src/fasta/kernel/redirecting_factory_body.dart:121:39)
#1      DillLibraryBuilder._addClass (package:front_end/src/fasta/dill/dill_library_builder.dart:202:34)
#2      List.forEach (dart:core-patch/growable_array.dart)
#3      DillLibraryBuilder.ensureLoaded (package:front_end/src/fasta/dill/dill_library_builder.dart:108:21)
#4      LazyLibraryScope.ensureScope (package:front_end/src/fasta/dill/dill_library_builder.dart:57:21)

#5      LazyScope._local (package:front_end/src/fasta/scope.dart:722:5)
#6      new ScopeNameIterator (package:front_end/src/fasta/scope.dart:1017:28)
#7      Scope.unfilteredNameIterator (package:front_end/src/fasta/scope.dart:146:16)
#8      Scope.filteredNameIterator (package:front_end/src/fasta/scope.dart:182:40)
#9      Import.finalizeImports (package:front_end/src/fasta/import.dart:78:60)
#10     SourceLibraryBuilder.addImportsToScope (package:front_end/src/fasta/source/source_library_builder.dart:1423:14)
#11     SourceLoader.computeLibraryScopes (package:front_end/src/fasta/source/source_loader.dart:1471:23)
#12     KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:423:14)
#13     withCrashReporting (package:front_end/src/fasta/crash.dart:136:24)
#14     KernelTarget.buildOutlines (package:front_end/src/fasta/kernel/kernel_target.dart:406:12)
#15     IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:408:59)
<asynchronous suspension>
#16     IncrementalCompiler.compile (package:vm/incremental_compiler.dart:68:50)
<asynchronous suspension>
#17     FrontendCompiler.recompileDelta (package:frontend_server/frontend_server.dart:847:52)
<asynchronous suspension>

the Dart compiler exited unexpectedly.
the Dart compiler exited unexpectedly.
Exited (1)

Relevant log output

No response

@nielsenko
Copy link
Contributor

@stevenosse It has been a while since I have seen a compiler crash. Last time was regarding the Finalizable interface dart-lang/sdk#49075.

Trying to follow your repro steps I must admit I cannot reproduce the issue. This is what I did

flutter create bomb
cd bomb
flutter pub add realm
flutter pub run realm install
flutter pub run realm generate --watch

Start vscode and edit main.dart to:

import 'package:flutter/material.dart';
import 'package:realm/realm.dart';

part 'main.g.dart';

@RealmModel()
class _Stuff {
  late int first;
}

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}

Run this on (I used the iPhone 14 Pro Max simulator).

Make a change - I replaced const Placeholder() with Container(color: Colors.red) - then hot-reload.. but it worked fine - no boom.

I tried more elaborate changes, like changing the actual realm model class _Stuff, or actually using it in the code, but I still cannot reproduce your issue.

Can you elaborate more on the exact steps you use? And perhaps a full project?

I tried both flutter 3.17.12 (current stable) and 3.11.0-2.0.pre.73 (current master).

@stevenosse
Copy link
Author

stevenosse commented May 9, 2023

Hello @nielsenko
Thanks for the quick reply.
I've investigated more on the issue. And I apologize, I should have dug deeper before creating the issue
I've tried to isolate the problem and it seems to occur when a nullable Realm Model is used in a freezed object

This breaks the compiler:

part 'dummy_state.freezed.dart';

@freezed
class DummyState with _$DummyState {
  factory DummyState({
    required Dummy item,
    RealmModel? storedItem,
  }) = _Initial;
}

To check this hypothesis, I redid the same one without freezed and the hot reload works again.

I continue the investigation.
Everything seems to work fine when the realm model is used in freezed like:

  • List type (eg. List<RealmModel>)
  • Non null attribute

@stevenosse stevenosse changed the title Hot reload not working when changes include realm models Hot reload does not work when changes include freezed models that embed a realm model May 9, 2023
@stevenosse stevenosse changed the title Hot reload does not work when changes include freezed models that embed a realm model Hot reload does not work when changes include freezed models that embed a nullable realm model May 9, 2023
@stevenosse
Copy link
Author

Answer from the Dart team: dart-lang/sdk#52312 (comment)

@sync-by-unito sync-by-unito bot closed this as completed May 15, 2023
@nielsenko
Copy link
Contributor

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants