Skip to content

Commit 47a5588

Browse files
Ilya Yanokcopybara-github
authored andcommitted
Don't try to compare fakes to real objects
Real object comparison sometimes tries to access private members, which are obvously missing on fakes. This results in confusing errors. To prevent those, just fail the comparison immediately if one thing is a fake while the other one is not. PiperOrigin-RevId: 571333761
1 parent 6b9eab9 commit 47a5588

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/src/invocation_matcher.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ class _MatcherEquality extends DeepCollectionEquality /* <Matcher | E> */ {
171171
if (e2 is Matcher && e1 is! Matcher) {
172172
return e2.matches(e1, {});
173173
}
174+
// If one thing is a `SmartFake` but not the other, always fail.
175+
// Otherwise the real thing might try calling private members on
176+
// fake, and that fails at runtime with confusing errors.
177+
if ((e1 is SmartFake) ^ (e2 is SmartFake)) return false;
178+
174179
return super.equals(e1, e2);
175180
}
176181

0 commit comments

Comments
 (0)