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

syntax parsing error when declaring const hook #203

Open
dickermoshe opened this issue Jun 14, 2024 · 2 comments
Open

syntax parsing error when declaring const hook #203

dickermoshe opened this issue Jun 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dickermoshe
Copy link

If you were to declare a top level constant hook and use it. You will get a build time error.
E.G.

const myHook = ChainedHook([]);

@MappableClass(hook: hook)
class Foo with FooMappable{
  final String? bar;
  Foo(this.bar)
}
The error was:
Could not format because the source could not be parsed:

line 122, column 40 of .: Expected to find '('.

122 │         final MappingHook hook = const myHook ;
    │                                        ^^^^^^^^^^^^^^^^^

There code here is not referring to the source code, it's referring to the code that dart_mappable created, before throwing it away once it detected a syntax error.

The issue here is that const should only appear when instantiating a Hook, not when referencing a constant.
image

@dickermoshe
Copy link
Author

dickermoshe commented Jun 14, 2024

@schultek Seems like a simple check here should suffice:

var hook = element.hookForClass;
if (hook != null) {
output.write('''
@override
final MappingHook hook = const $hook;
''');
}

@schultek
Copy link
Owner

Indeed a bug, let me look into it.

@schultek schultek added the bug Something isn't working label Jan 17, 2025
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