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

Some keyword escaping happens in the wrong places #1441

Closed
provokateurin opened this issue Jan 11, 2024 · 7 comments · Fixed by #1511 or #1545
Closed

Some keyword escaping happens in the wrong places #1441

provokateurin opened this issue Jan 11, 2024 · 7 comments · Fixed by #1511 or #1545
Assignees
Labels
bug Something isn't working package: dynamite

Comments

@provokateurin
Copy link
Member

Type must be added as a keyword to avoid collisions.
I quickly tried adding it, but then generating leads to these errors:

Error in BuiltValueGenerator for /nextcloud/lib/src/api/files_external.openapi.dart.
Please make the following changes to use EnumClass:

1. Have exactly one constructor: const Mount_$Type._(String name) : super(name); or in Dart>=2.17: const Mount_$Type._(super.name);
2. Add getter: static BuiltSet<Mount_$Type> get values => _$values
3. Add method: static Mount_$Type valueOf(String name) => _$valueOf(name)
4. Have exactly one constructor: const StorageConfig_$Type._(String name) : super(name); or in Dart>=2.17: const StorageConfig_$Type._(super.name);
5. Add getter: static BuiltSet<StorageConfig_$Type> get values => _$values
6. Add method: static StorageConfig_$Type valueOf(String name) => _$valueOf(name)

I believe this is generating bad code where Type is now also escaped inside the name:

class Mount_$Type extends EnumClass {
  const Mount_$Type._(super.name);

  /// `dir`
  static const Mount_$Type dir = _$mount$TypeDir;

  /// Returns a set with all values this enum contains.
  // coverage:ignore-start
  static BuiltSet<Mount_$Type> get values => _$mount$TypeValues;
  // coverage:ignore-end

  /// Returns the enum value associated to the [name].
  static Mount_$Type valueOf(String name) => _$valueOfMount_$Type(name);

  /// Returns the serialized value of this enum value.
  String get value => _$jsonSerializers.serializeWith(serializer, this)! as String;

  /// Serializer for Mount_$Type.
  @BuiltValueSerializer(custom: true)
  static Serializer<Mount_$Type> get serializer => const _$Mount_$TypeSerializer();
}

@Leptopoda do you mind taking a look? This is breaking the update to the latest specs :/

@provokateurin provokateurin added bug Something isn't working package: dynamite labels Jan 11, 2024
@Leptopoda
Copy link
Member

I think you are running into #1398

There was a reason why I alsso added the escaping to the enum but can't remember why. I'll take a look.

Maybe a PR for upstream is easier.

@Leptopoda Leptopoda self-assigned this Jan 11, 2024
@Leptopoda
Copy link
Member

I've made a PR upstream.
google/built_value.dart#1297

@provokateurin
Copy link
Member Author

Yep, looks like your PR will fix it.

@provokateurin
Copy link
Member Author

This still happens. With the example above it is not necessary to add the dollar sign because it is in the middle of the name, so we shouldn't do it to keep it more readable.

@provokateurin provokateurin reopened this Jan 24, 2024
@provokateurin
Copy link
Member Author

At least the code is now correctly generated after your upstream fix.

@Leptopoda
Copy link
Member

So this is now only cosmetic?
As mentioned above there where reasons why I did this (but I can't remember). I'll dive into it in the coming days.

@provokateurin
Copy link
Member Author

Only cosmetic, but it also is a breaking change (see the PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: dynamite
Projects
None yet
2 participants