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

Freezed Fails To Generate Class Depending on Line Break #1049

Closed
gabrielmcreynolds opened this issue Mar 13, 2024 · 1 comment
Closed

Freezed Fails To Generate Class Depending on Line Break #1049

gabrielmcreynolds opened this issue Mar 13, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@gabrielmcreynolds
Copy link

Describe the bug
I have a class which is generated by freezed and contains a Default decorator on a IList property. Whenever the decorator and the type are on the same line the freezed generator breaks, if they are on different lines it works.

BuildRunner Failed Output

freezed on lib/model.dart: An error `FormatterException` occurred while formatting the generated source for `package:freezed_line_length_issue/model.dart` which was output to `lib/model.freezed.dart`. This may indicate an issue in the generator, the input source code, or in the source formatter. Could not format because the source could not be parsed:

line 20, column 27 of .: Expected an identifier.

20 │ IListConst([])) IList get serverTrails => throw _privateConstructorUsedError;
│ ^

line 20, column 29 of .: A function body must be provided.

20 │ IListConst([])) IList get serverTrails => throw _privateConstructorUsedError;
│ ^

line 20, column 29 of .: Expected a class member.

20 │ IListConst([])) IList get serverTrails => throw _privateConstructorUsedError;
│ ^

line 38, column 27 of .: Expected an identifier.

38 │ IListConst([])) IList serverTrails
│ ^

line 38, column 29 of .: Expected to find '}'.

38 │ IListConst([])) IList serverTrails
│ ^

line 57, column 27 of .: Expected to find ','.

57 │ as IListConst([])) IList,
│ ^

line 57, column 33 of .: Expected to find ','.

57 │ as IListConst([])) IList,
│ ^^^^^

line 58, column 7 of .: Expected to find ';'.

58 │ )as $Val);
│ ^^^^

line 58, column 11 of .: Expected an identifier.

58 │ )as $Val);
│ ^

line 58, column 11 of .: Unexpected text ';'.

58 │ )as $Val);
│ ^

(17 more errors...)
[INFO] Running build completed, took 37ms
[INFO] Caching finalized dependency graph completed, took 38ms
[SEVERE] Failed after 79ms

To Reproduce

//model.dart
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:freezed_line_length_issue/trail.dart';

part 'model.freezed.dart';

@freezed
class Model with _$Model {
  const Model._();

  const factory Model({
    @Default(IListConst<ServerTrail>([])) IList<ServerTrail> serverTrails, // if IList<ServerTrail> serverTrails is on new line it succeeds
  }) = _Model;
}

For completeness here is trail.dart

import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'trail.freezed.dart';

@freezed
sealed class Trail with _$Trail {
  const Trail._();

  const factory Trail.FromServer({
    required String id,
    required IList<num> points,
  }) = ServerTrail;
}

Expected behavior
Build runner would generate types w/out throwing errors regardless of whether the Default decorator is on its own line.

@gabrielmcreynolds
Copy link
Author

gabrielmcreynolds commented Mar 13, 2024

Somehow accidentally duplicated ticket. Closing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants