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

FormatterException while generating code #12

Open
wizard11 opened this issue Nov 11, 2020 · 2 comments
Open

FormatterException while generating code #12

wizard11 opened this issue Nov 11, 2020 · 2 comments

Comments

@wizard11
Copy link

Hi, I was trying to run the example given in the package. But when I run the code generator I get the following exception.

[SEVERE] built_union_generator:built_value on lib/models/union.dart:
An error `FormatterException` occurred while formatting the generated source for
  `package:basicappl/models/union.dart`
which was output to
  `lib/models/union.built_union.g.part`.
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 28: Expected to find ')'.
   ╷
20 │ _$SimpleUnion.string(String* string): _type = _$SimpleUnionType.string, assert(string != null, '_$SimpleUnion constructor argument string can not be null!'), _values = [string];
   │                            ^
   ╵
line 24, column 25: Expected to find ')'.
   ╷
24 │ @required T Function(int*) integer,
   │                         ^
   ╵
line 101, column 66: Expected an identifier.
    ╷
101 │ serializers.serialize(integer, specifiedType: const FullType(int*))
    │                                                                  ^
    ╵
line 108, column 142: Expected an identifier.
    ╷
108 │ serializers.serialize(tupleInt, specifiedType: const FullType(int*)),serializers.serialize(tupleString, specifiedType: const FullType(String*))
    │                                                                                                                                              ^
    ╵
line 19, column 24: Expected to find ')'.
   ╷
19 │ _$SimpleUnion.tuple(int* tupleInt,String* tupleString): _type = _$SimpleUnionType.tuple, assert(tupleInt != null, '_$SimpleUnion constructor argument tupleInt can not be null!'), assert(tupleString != null, '_$SimpleUnion constructor argument tupleString can not be null!'), _values = [tupleInt,tupleString];
   │                        ^
   ╵
line 132, column 106: Expected an identifier.
    ╷
132 │ result = SimpleUnion.integer(serializers.deserialize(iterator.current, specifiedType: const FullType(int*)));
    │                                                                                                          ^
    ╵
line 25, column 25: Expected to find ')'.
   ╷
25 │ @required T Function(int*,String*) tuple,
   │                         ^
   ╵
line 142, column 68: Expected an identifier.
    ╷
142 │ serializers.deserialize(tupleInt,specifiedType: const FullType(int*)),
    │                                                                    ^
    ╵
line 26, column 28: Expected to find ')'.
   ╷
26 │ @required T Function(String*) string,
   │                            ^
   ╵
line 148, column 108: Expected an identifier.
    ╷
148 │ result = SimpleUnion.string(serializers.deserialize(iterator.current, specifiedType: const FullType(String*)));
    │                                                                                                            ^
    ╵

This is the exact code in my model file

import 'package:built_union/built_union.dart';
import 'package:built_value/serializer.dart';

part 'union.g.dart';

@BuiltUnion()
class SimpleUnion extends _$SimpleUnion {
  static Serializer<SimpleUnion> get serializer => _$simpleUnionSerializer;

  SimpleUnion.empty() : super.empty();
  SimpleUnion.integer(int integer) : super.integer(integer);
  SimpleUnion.tuple(int tupleInt, String tupleString)
      : super.tuple(tupleInt, tupleString);
  SimpleUnion.string(String string) : super.string(string);
  SimpleUnion.builtList(BuiltList<int> builtList) : super.builtList(builtList);
}

And these are dependencies I am using -

dependencies:
  meta: ^1.2.3
  built_union: ^0.1.3

dev_dependencies:
  built_union_generator: ^0.1.3
  build_runner: 1.10.1
  built_value_generator: 7.1.0

Could you please let me know, what is causing this issue?

@realcr
Copy link
Member

realcr commented Nov 11, 2020

Hey @wizard11, thanks for sending this issue.

I just quickly checked on my side (although with a bit different list of dependencies), and I couldn't reproduce the issue. Maybe something else is different between our setups.

One thing that I already managed to see is the asterisk (*) symbol that got into many strange places in the generated code on your setup, and I am not sure why it happens. Example:

26@required T Function(String*) string,
                                ^

It might take a while before I manage to dive into this. For now, here are some ways in which we might be able to debug the issue:

  1. Try to clone the repository (git clone https://github.com/freedomlayer/built_union.dart). Then run tool/presubmit and see if the tests pass. If they don't, it will be very helpful if you could provide the output you see on your machine.

  2. Try to change the dependencies you use to the older dependencies specified in the project's readme, just to see if any new version in one of the dependencies is what causing this issue. I would try to do this gradually, to see where the breakage happens.

@wizard11
Copy link
Author

Thanks @realcr for the timely response. I highly appreciate it.

I tried option 1, all the tests passed with a minor modification of sed to gsed in the local_deps script as I am using Mac. Could MacOS be causing this issue somehow?

For option 2, I changed all my current dependencies to the ones given in project's README, even the built_value & built_value_generator ones too. But I am still seeing the same exception. My project has many more dependencies, probably one of them is causing the issue.

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

2 participants