-
Notifications
You must be signed in to change notification settings - Fork 166
Account for records in type relatedness checks #4266
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super awesome!
Might be good to have @bwilkerson take a quick look but LGTM!
@@ -282,6 +261,39 @@ class InterfaceTypeDefinition { | |||
} | |||
} | |||
|
|||
extension on TypeSystem { | |||
bool interfaceTypesAreUnrelated(InterfaceType type1, InterfaceType type2) { | |||
// In this case, [leftElement] and [rightElement] each represent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming the parameters to leftElement
and rightElement
. I think they read better. Otherwise, consider updating the comments to match the current names.
(And I don't understand what "this case" is referring to here, but that's not your problem because you didn't write the original code.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good note; renamed.
I also really didn't understand what that comment referred to. After looking for a few minutes, I decided to just remove it.
@@ -18,6 +18,28 @@ class UnrelatedTypeEqualityChecksTestLanguage300 extends LintRuleTest | |||
@override | |||
String get lintRule => 'unrelated_type_equality_checks'; | |||
|
|||
test_recordAndInterfaceType_unrelated() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have some tests involving records with named fields, and maybe some that have both positional and named fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Fixes dart-lang/sdk#59108
Uses
isAssignableTo
to handle relatedness, accounting for shape and subtypes.