dart_mappable icon indicating copy to clipboard operation
dart_mappable copied to clipboard

syntax parsing error when declaring const hook

Open dickermoshe opened this issue 1 year ago • 2 comments

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 avatar Jun 14 '24 18:06 dickermoshe

@schultek Seems like a simple check here should suffice: https://github.com/schultek/dart_mappable/blob/4777e79cdc99e15730d18990e1d774edc0064b0a/packages/dart_mappable_builder/lib/src/generators/mixins/decoding_mixin.dart#L11-L17

dickermoshe avatar Jun 14 '24 18:06 dickermoshe

Indeed a bug, let me look into it.

schultek avatar Jun 30 '24 20:06 schultek

I finally got to work on it. Fixed in v4.5.0

schultek avatar Mar 13 '25 20:03 schultek