@@ -436,8 +436,10 @@ sealed class InstanceReference extends Reference {
436436 : final named,
437437 : final positional,
438438 : final loadingUnitIndices,
439+ : final definitionIndex,
439440 ) =>
440441 InstanceCreationReference (
442+ definition: context.definitions[definitionIndex],
441443 positionalArguments: (positional ?? [])
442444 .map ((index) => CallReference ._argumentFromSyntax (index, context))
443445 .toList (),
@@ -451,8 +453,12 @@ sealed class InstanceReference extends Reference {
451453 .map ((index) => context.loadingUnits[index])
452454 .toList (),
453455 ),
454- TearoffInstanceSyntax (: final loadingUnitIndices) =>
456+ TearoffInstanceSyntax (
457+ : final loadingUnitIndices,
458+ : final definitionIndex,
459+ ) =>
455460 ConstructorTearoffReference (
461+ definition: context.definitions[definitionIndex],
456462 loadingUnits: loadingUnitIndices
457463 .map ((index) => context.loadingUnits[index])
458464 .toList (),
@@ -567,10 +573,12 @@ final class InstanceConstantReference extends InstanceReference {
567573}
568574
569575final class InstanceCreationReference extends InstanceReference {
576+ final Definition definition;
570577 final List <MaybeConstant > positionalArguments;
571578 final Map <String , MaybeConstant > namedArguments;
572579
573580 const InstanceCreationReference ({
581+ required this .definition,
574582 required this .positionalArguments,
575583 required this .namedArguments,
576584 required super .loadingUnits,
@@ -581,6 +589,7 @@ final class InstanceCreationReference extends InstanceReference {
581589 final sortedNamedArgs = namedArguments.entries.toList ()
582590 ..sort ((a, b) => a.key.compareTo (b.key));
583591 return InstanceCreationReference (
592+ definition: context.canonicalizeDefinition (definition),
584593 loadingUnits: [
585594 for (final u in loadingUnits) context.canonicalizeLoadingUnit (u),
586595 ],
@@ -597,6 +606,7 @@ final class InstanceCreationReference extends InstanceReference {
597606 @override
598607 InstanceReference _filter ({String ? definitionPackageName}) =>
599608 InstanceCreationReference (
609+ definition: definition,
600610 loadingUnits: loadingUnits,
601611 positionalArguments: [
602612 for (final c in positionalArguments)
@@ -618,6 +628,7 @@ final class InstanceCreationReference extends InstanceReference {
618628 }
619629
620630 return CreationInstanceSyntax (
631+ definitionIndex: context.definitions[definition]! ,
621632 loadingUnitIndices: [
622633 for (final unit in loadingUnits) context.loadingUnits[unit]! ,
623634 ],
@@ -637,13 +648,15 @@ final class InstanceCreationReference extends InstanceReference {
637648 if (! (super == other)) return false ;
638649
639650 return other is InstanceCreationReference &&
651+ other.definition == definition &&
640652 deepEquals (other.positionalArguments, positionalArguments) &&
641653 deepEquals (other.namedArguments, namedArguments);
642654 }
643655
644656 @override
645657 int get hashCode => cacheHashCode (
646658 () => Object .hash (
659+ definition,
647660 deepHash (positionalArguments),
648661 deepHash (namedArguments),
649662 super .hashCode,
@@ -660,6 +673,10 @@ final class InstanceCreationReference extends InstanceReference {
660673 bool allowPromotionOfUnsupported = false ,
661674 }) {
662675 if (other is ! InstanceCreationReference ) return false ;
676+ // ignore: invalid_use_of_visible_for_testing_member
677+ if (! definition.semanticEquals (other.definition, uriMapping: uriMapping)) {
678+ return false ;
679+ }
663680 if (positionalArguments.length != other.positionalArguments.length) {
664681 return false ;
665682 }
@@ -699,6 +716,7 @@ final class InstanceCreationReference extends InstanceReference {
699716 @override
700717 String toString () {
701718 final parts = < String > [];
719+ parts.add ('definition: $definition ' );
702720 if (positionalArguments.isNotEmpty) {
703721 parts.add ('positional: ${positionalArguments .join (', ' )}' );
704722 }
@@ -718,11 +736,17 @@ final class InstanceCreationReference extends InstanceReference {
718736}
719737
720738final class ConstructorTearoffReference extends InstanceReference {
721- const ConstructorTearoffReference ({required super .loadingUnits});
739+ final Definition definition;
740+
741+ const ConstructorTearoffReference ({
742+ required this .definition,
743+ required super .loadingUnits,
744+ });
722745
723746 @override
724747 Reference _canonicalizeChildren (CanonicalizationContext context) =>
725748 ConstructorTearoffReference (
749+ definition: context.canonicalizeDefinition (definition),
726750 loadingUnits: [
727751 for (final u in loadingUnits) context.canonicalizeLoadingUnit (u),
728752 ],
@@ -734,11 +758,25 @@ final class ConstructorTearoffReference extends InstanceReference {
734758 @override
735759 TearoffInstanceSyntax _toSyntax (SerializationContext context) =>
736760 TearoffInstanceSyntax (
761+ definitionIndex: context.definitions[definition]! ,
737762 loadingUnitIndices: [
738763 for (final unit in loadingUnits) context.loadingUnits[unit]! ,
739764 ],
740765 );
741766
767+ @override
768+ bool operator == (Object other) {
769+ if (identical (this , other)) return true ;
770+ if (! (super == other)) return false ;
771+
772+ return other is ConstructorTearoffReference &&
773+ other.definition == definition;
774+ }
775+
776+ @override
777+ int get hashCode =>
778+ cacheHashCode (() => Object .hash (definition, super .hashCode));
779+
742780 @override
743781 @visibleForTesting
744782 bool semanticEquals (
@@ -749,6 +787,10 @@ final class ConstructorTearoffReference extends InstanceReference {
749787 bool allowPromotionOfUnsupported = false ,
750788 }) {
751789 if (other is ! ConstructorTearoffReference ) return false ;
790+ // ignore: invalid_use_of_visible_for_testing_member
791+ if (! definition.semanticEquals (other.definition, uriMapping: uriMapping)) {
792+ return false ;
793+ }
752794 return _semanticEqualsShared (
753795 other,
754796 uriMapping: uriMapping,
@@ -759,6 +801,7 @@ final class ConstructorTearoffReference extends InstanceReference {
759801 @override
760802 String toString () {
761803 final parts = < String > [];
804+ parts.add ('definition: $definition ' );
762805 if (loadingUnits.isNotEmpty) {
763806 parts.add ('loadingUnits: ${loadingUnits .map ((u ) => u .name ).join (', ' )}' );
764807 }
0 commit comments