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

Can't specify a nested list type with @Default() #991

Open
Reprevise opened this issue Oct 9, 2023 · 1 comment
Open

Can't specify a nested list type with @Default() #991

Reprevise opened this issue Oct 9, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Reprevise
Copy link

Reprevise commented Oct 9, 2023

Describe the bug
When specifying a nested list type using @Default() like so: @Default(<List<dynamic>>[]), the generated code errors. If you use @Default(<List>[]) instead, it works fine.

Error details
[SEVERE] freezed on lib/example.dart:
An error `FormatterException` occurred while formatting the generated source for
`package:small_dart/example.dart`
which was output to
`lib/example.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 43, column 52 of .: Expected to find '}'.
 ╷
43 │   const _$ExampleClassImpl({final  List<dynamic>>[]) List<List<dynamic>> data = const <List<dynamic>>[]}): _data = data;
 │                                                    ^
 ╵
line 20, column 2 of .: Methods must have an explicit list of parameters.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │  ^^^^
 ╵
line 20, column 15 of .: A function body must be provided.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │               ^
 ╵
line 20, column 15 of .: Operator declarations must be preceded by the keyword 'operator'.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │               ^
 ╵
line 20, column 15 of .: Methods must have an explicit list of parameters.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │               ^
 ╵
line 20, column 16 of .: A function body must be provided.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │                ^^
 ╵
line 20, column 16 of .: Operator declarations must be preceded by the keyword 'operator'.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │                ^^
 ╵
line 20, column 16 of .: Methods must have an explicit list of parameters.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │                ^^
 ╵
line 20, column 18 of .: A function body must be provided.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │                  ^
 ╵
line 20, column 18 of .: Expected a class member.
 ╷
20 │  List<dynamic>>[]) List<List<dynamic>> get data => throw _privateConstructorUsedError;
 │                  ^
 ╵

To Reproduce

Run build_runner on the class below:

import 'package:freezed_annotation/freezed_annotation.dart';

part 'example.freezed.dart';

@freezed
class ExampleClass with _$ExampleClass {
  const factory ExampleClass({
    @Default(<List<dynamic>>[]) List<List<dynamic>> data,
  }) = _ExampleClass;
}

Expected behavior
The build_runner process should've completed successfully and the generated code should be correct with no errors.

@Reprevise Reprevise added bug Something isn't working needs triage labels Oct 9, 2023
@rrousselGit
Copy link
Owner

A workaround would be:

const _dataDefault = <List<dynamic>>[];

@freezed
class ExampleClass with _$ExampleClass {
  const factory ExampleClass({
    @Default(_dataDefault) List<List<dynamic>> data,
  }) = _ExampleClass;
}

This bug is low priority for me at the moment. If you're interested in it, make sure to 👍 the issue.
Or make a PR if you feel like it :)

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

No branches or pull requests

2 participants