-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Produce a more helpful error for
isInstanceOf(int.class)
and simila…
…r, and make analogous `isNotInstanceOf` calls fail. Users should write `isInstanceOf(Integer.class)` instead. As always, the biggest danger is in `isNotInstanceOf` assertions, which currently silently pass for any input if given a primitive type. If we wanted, we could automatically treat `int.class` like `Integer.class`. But I think we can get away with being stricter, and I think it's clearest to have users write the boxed type: It's not as if Truth can tell whether its input was "originally" an `int` or not. (As a followup, I was considering also rejecting `Void.class`. But such a change seems as likely to break someone's clever "make this always pass/fail" hack than to detect real problems. Still, it may be worth a thought someday.) Before: ``` expected instance of: int but was instance of : java.lang.Integer with value : 1 ``` After: ``` java.lang.IllegalArgumentException: Cannot check instanceof for primitive type int. Pass the wrapper class instead. ``` RELNOTES=n/a PiperOrigin-RevId: 478924507
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters