-
Notifications
You must be signed in to change notification settings - Fork 52
Add Decimal
prefix to extensions
#112
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
base: master
Are you sure you want to change the base?
Add Decimal
prefix to extensions
#112
Conversation
I just try the following code and see no error from analyzer with Dart-3.8.1: import 'package:decimal/decimal.dart';
import 'package:rational/rational.dart';
void main() {
print(1.toDecimal());
print(1.toRational());
print(BigInt.one.toDecimal());
print(BigInt.one.toRational());
} What's your Dart version? |
It could be 3.6.x IIRC. |
Okay it was about exporting them simultaneously, not importing. Sorry for the confusion. export 'package:decimal/decimal.dart' show BigIntExt;
export 'package:rational/rational.dart' show BigIntExt; This will raise: The name 'BigIntExt' is defined in the libraries 'package:decimal/decimal.dart' and 'package:rational/rational.dart'.
Try removing the export of one of the libraries, or explicitly hiding the name in one of the export directives. |
TBH I'm not a big fan of this change. This kind of export of the same name is really uncommon IMHO. OTOH I can't find a workaroud to make it work without renaming. It could be worth it asking on dart-lang/language. |
The example was the minimum, the actual case is I want to export both packages for using: export 'package:decimal/decimal.dart';
export 'package:rational/rational.dart'; Which will also raise the lint. In some cases, I also needed |
I think the issue is a language issue (but I can't find a relevant issue number on https://github.com/dart-lang/language). eg. a language solution could be to allow typedef on extension:
A workaround can be to duplicate the code : export 'package:decimal/decimal.dart' hide IntExt, BigIntExt;
export 'package:rational/rational.dart' hide IntExt, BigIntExt;
import 'package:decimal/decimal.dart';
import 'package:rational/rational.dart';
/// Extensions on [BigInt].
extension BigIntExt on BigInt {
/// This [BigInt] as a [Rational].
Rational toRational() => Rational(this);
/// This [BigInt] as a [Decimal].
Decimal toDecimal() => Decimal.fromBigInt(this);
}
/// Extensions on [int].
extension IntExt on int {
/// This [int] as a [Rational].
Rational toRational() => Rational.fromInt(this);
/// This [int] as a [Decimal].
Decimal toDecimal() => Decimal.fromInt(this);
} |
Indeed, I shall file an issue referencing this. Should we continue or wait until a fix for the language has been implemented? |
If you can live with the above workaround I'll prefer to wait for an answer of the language issue you will file |
When I was trying to import
package:decimal
andpackage:rational
simultaneously, the analyzer complained that they had a conflicting set of extensions.P.S. I would not expect the change to be a breaking change.