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

Invalid code generation when class starts with $ #28

Closed
JCKodel opened this issue Jun 11, 2024 · 2 comments
Closed

Invalid code generation when class starts with $ #28

JCKodel opened this issue Jun 11, 2024 · 2 comments

Comments

@JCKodel
Copy link

JCKodel commented Jun 11, 2024

This code:

@DataClass()
final class $UserIsAuthenticating with _$$UserIsAuthenticating {
  const $UserIsAuthenticating({required this.principal});

  final Principal principal;
}

generates this method:

@override
String toString() => (ClassToString('$UserIsAuthenticating')
      ..add('principal', _self.principal))
    .toString();
}

So Dart considers the $ as the string interpolator.

Fix: the generator should sanitize $ characters or using raw strings (using the r string prefix):

@override
String toString() => (ClassToString(r'$UserIsAuthenticating')
      ..add('principal', _self.principal))
    .toString();
}

final classToString = "ClassToString('${classSpec.self.name}'$types)${fields.join()}";

@BreX900
Copy link
Owner

BreX900 commented Jan 5, 2025

You should not use dollar signs to name your classes since anything that starts with a dollar sign is usually generated.

@BreX900
Copy link
Owner

BreX900 commented Jan 5, 2025

Fixes in release 2.0.2

@BreX900 BreX900 closed this as completed Jan 5, 2025
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