-
-
Notifications
You must be signed in to change notification settings - Fork 240
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 #1048
Comments
Freezed classes do not support generated types as inputs. You'll have to wait for metaprogramming for this. Do you still have the issue when not using |
I'm a bit confused about this statement. If that is true then why would it work perfectly fine if the I think the issue is with the |
There's likely a bug here. It's just that your current sample uses patterns that aren't supported Overall I don't have too much time to investigate this. Feel free to open a PR :) |
Faced the same issue and got it working by replacing with typedef. Very strange behavior. import 'package:freezed_annotation/freezed_annotation.dart';
part 'filter_cache_state.freezed.dart';
typedef AcceptanceReportFilter = Map<AcceptanceReportFilterType,
ListFilter<dynamic, AcceptanceReportFilterType>>;
@freezed
class FilterCacheState with _$FilterCacheState {
const factory FilterCacheState({
required Session? session,
required Map<IssueFilterType, ListFilter<dynamic, IssueFilterType>>?
issueFilter,
required Map<JournalFilterType, ListFilter<dynamic, JournalFilterType>>?
journalFilter,
// This doesn't work as reported in bug with linebreak
required Map<AcceptanceReportFilterType,
ListFilter<dynamic, AcceptanceReportFilterType>>?
acceptanceReportFilter,
// Replacing same with typedef above works
// required AcceptanceReportFilter? acceptanceReportFilter,
}) = _FilterCacheState;
factory FilterCacheState.empty({required Session session}) =>
FilterCacheState(
session: session,
issueFilter: null,
journalFilter: null,
acceptanceReportFilter: null,
);
factory FilterCacheState.noSession() => const FilterCacheState(
session: null,
issueFilter: null,
journalFilter: null,
acceptanceReportFilter: null,
);
}
enum AcceptanceReportFilterType {
freeText,
creator,
} |
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
For completeness here is trail.dart
Expected behavior
Build runner would generate types w/out throwing errors regardless of whether the Default decorator is on its own line.
The text was updated successfully, but these errors were encountered: