Skip to content

Conversation

AlexV525
Copy link
Contributor

@AlexV525 AlexV525 commented Mar 3, 2025

When I was trying to import package:decimal and package:rational simultaneously, the analyzer complained that they had a conflicting set of extensions.

The name 'BigIntExt' is defined in the libraries 'package:decimal/decimal.dart' and 'package:rational/rational.dart'.

P.S. I would not expect the change to be a breaking change.

@a14n
Copy link
Owner

a14n commented Jun 15, 2025

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?

@AlexV525
Copy link
Contributor Author

It could be 3.6.x IIRC.

@AlexV525
Copy link
Contributor Author

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.

@a14n
Copy link
Owner

a14n commented Jun 19, 2025

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.
Out of curriosity why are you exporting whose one together? I expected to use one or the other, not both.

@AlexV525
Copy link
Contributor Author

AlexV525 commented Jun 21, 2025

This kind of export of the same name is really uncommon IMHO.
Out of curriosity why are you exporting whose one together? I expected to use one or the other, not both.

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 Rational, such as / operator and pow method. Those classes didn't get exported from package:decimal so I need to import package:rational as an extra effort. Then I came up with the idea to export them both from my general export point.

@a14n
Copy link
Owner

a14n commented Jun 22, 2025

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:


export 'package:decimal/decimal.dart' hide IntExt, BigIntExt;
export 'package:rational/rational.dart' hide IntExt, BigIntExt;
import 'package:decimal/decimal.dart' as decimal;
import 'package:rational/rational.dart' as  rational;

typedef DecimalBigIntExt = decimal.BigIntExt;
typedef DecimalIntExt = decimal.IntExt;
typedef RationalBigIntExt = rational.BigIntExt;
typedef RationalIntExt = rational.IntExt;

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);
}

@AlexV525
Copy link
Contributor Author

I think the issue is a language issue.

Indeed, I shall file an issue referencing this.

Should we continue or wait until a fix for the language has been implemented?

@a14n
Copy link
Owner

a14n commented Jun 23, 2025

If you can live with the above workaround I'll prefer to wait for an answer of the language issue you will file

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

Successfully merging this pull request may close these issues.

2 participants