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

Code generation error when argument involves typedef List and a default value #2128

Open
mernen opened this issue Jan 11, 2025 · 1 comment

Comments

@mernen
Copy link
Contributor

mernen commented Jan 11, 2025

Given this file:

typedef Strings = List<String>;

@RoutePage()
class TestPage extends StatelessWidget {
  const TestPage({
    super.key,
    this.strings = const [],
  });

  final Strings strings;

  @override
  Widget build(BuildContext context) => const Placeholder();
}

auto_route_generator fails to produce the routes file with an error like:

Full output
line 109, column 133 of .: Expected an identifier.
    ╷
109 │ class TestPageRoute extends _i47.PageRouteInfo<TestPageRouteArgs> {TestPageRoute({_i48.Key? key, _i46.Strings strings = const _i46. [], List<_i47.PageRouteInfo>? children, }) : super(TestPageRoute.name, args: TestPageRouteArgs(key: key, strings: strings, ), initialChildren: children, );
    │                                                                                                                                     ^^
    ╵
line 109, column 133 of .: Expected to find '('.
    ╷
109 │ class TestPageRoute extends _i47.PageRouteInfo<TestPageRouteArgs> {TestPageRoute({_i48.Key? key, _i46.Strings strings = const _i46. [], List<_i47.PageRouteInfo>? children, }) : super(TestPageRoute.name, args: TestPageRouteArgs(key: key, strings: strings, ), initialChildren: children, );
    │                                                                                                                                     ^^
    ╵
line 109, column 134 of .: Expected an identifier.
    ╷
109 │ class TestPageRoute extends _i47.PageRouteInfo<TestPageRouteArgs> {TestPageRoute({_i48.Key? key, _i46.Strings strings = const _i46. [], List<_i47.PageRouteInfo>? children, }) : super(TestPageRoute.name, args: TestPageRouteArgs(key: key, strings: strings, ), initialChildren: children, );
    │                                                                                                                                      ^
    ╵
line 117, column 88 of .: Expected an identifier.
    ╷
117 │ class TestPageRouteArgs {const TestPageRouteArgs({this.key, this.strings = const _i46. [], });
    │                                                                                        ^^
    ╵
line 117, column 88 of .: Expected to find '('.
    ╷
117 │ class TestPageRouteArgs {const TestPageRouteArgs({this.key, this.strings = const _i46. [], });
    │                                                                                        ^^
    ╵
line 117, column 89 of .: Expected an identifier.
    ╷
117 │ class TestPageRouteArgs {const TestPageRouteArgs({this.key, this.strings = const _i46. [], });
    │                                                                                         ^
    ╵

The most relevant part is that it tried to add a namespace to the array literal:

_i46.Strings strings = const _i46. []

It works fine if we write List<String> directly like this:

  final List<String> strings;

This is a regression from auto_route_generator v5, which handled typedefs well.

@mernen
Copy link
Contributor Author

mernen commented Jan 11, 2025

For comparison, auto_route_generator v5.0.2 produced simply const []. I don't know when exactly the regression was introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant