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

Dollar sign in unionKey value breaks build #274

Closed
refi64 opened this issue Oct 5, 2020 · 0 comments
Closed

Dollar sign in unionKey value breaks build #274

refi64 opened this issue Oct 5, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@refi64
Copy link

refi64 commented Oct 5, 2020

Describe the bug

If the value of unionKey has a $, the build fails.

To Reproduce

From my application, but stripped down:

const clientToHostUnionKey = r'$stratosMessageType';

@Freezed(unionKey: clientToHostUnionKey)
abstract class ClientToHostMessage with _$ClientToHostMessage {
  factory ClientToHostMessage.requestSync(String id) = RequestSync;
  factory ClientToHostMessage.requestSyncAll() = RequestSyncAll;

  factory ClientToHostMessage.fromJson(Map<String, dynamic> json) =>
      _$ClientToHostMessageFromJson(json);
}

Expected behavior
Compilation to succeed. Instead, I get (this was from a slightly larger repro, hence why there are some branches mentioned in the error that aren't in the above example):

packages/stratos/message.freezed.dart:12:18:
Error: Getter not found: 'stratosMessageType'.
  switch (json['$stratosMessageType'] as String) {
                 ^^^^^^^^^^^^^^^^^^
packages/stratos/message.freezed.dart:228:12:
Error: The getter 'stratosMessageType' isn't defined for the class '_$LatestCaptures'.
 - '_$LatestCaptures' is from 'package:stratos/message.dart' ('packages/stratos/message.dart').
      ..['$stratosMessageType'] = 'latestCaptures';
           ^^^^^^^^^^^^^^^^^^
packages/stratos/message.freezed.dart:362:44:
Error: The getter 'stratosMessageType' isn't defined for the class '_$RequestSync'.
 - '_$RequestSync' is from 'package:stratos/message.dart' ('packages/stratos/message.dart').
    return _$_$RequestSyncToJson(this)..['$stratosMessageType'] = 'requestSync';
                                           ^^^^^^^^^^^^^^^^^^
packages/stratos/message.freezed.dart:476:12:
Error: The getter 'stratosMessageType' isn't defined for the class '_$RequestSyncAll'.
 - '_$RequestSyncAll' is from 'package:stratos/message.dart' ('packages/stratos/message.dart').
      ..['$stratosMessageType'] = 'requestSyncAll';
           ^^^^^^^^^^^^^^^^^^
Error: Compilation failed.

so it definitely seems like the unionKey value isn't being escaped properly.

Side note: this lib is pretty awesome, I've tried a bunch of Dart union libraries and this is definitely one of my favorites.

@refi64 refi64 added bug Something isn't working needs triage labels Oct 5, 2020
rrousselGit added a commit that referenced this issue Oct 11, 2020
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