@@ -1121,7 +1121,7 @@ bool TypeConstraint::checkNamedTypeNonObj(tv_rval val) const {
1121
1121
case AnnotAction::ConvertClass:
1122
1122
case AnnotAction::WarnLazyClass:
1123
1123
case AnnotAction::ConvertLazyClass:
1124
- // verifyFail will deal with the conversion/warning
1124
+ // verify*Fail will deal with the conversion/warning
1125
1125
return false ;
1126
1126
case AnnotAction::WarnClassname:
1127
1127
if (folly::Random::oneIn (RO::EvalClassnameNoticesSampleRate)) {
@@ -1344,7 +1344,7 @@ bool TypeConstraint::checkImpl(tv_rval val,
1344
1344
case AnnotAction::ConvertClass:
1345
1345
case AnnotAction::WarnLazyClass:
1346
1346
case AnnotAction::ConvertLazyClass:
1347
- // verifyFail will deal with the conversion/warning
1347
+ // verify*Fail will deal with the conversion/warning
1348
1348
return false ;
1349
1349
case AnnotAction::WarnClassname:
1350
1350
if (folly::Random::oneIn (RO::EvalClassnameNoticesSampleRate)) {
@@ -1669,19 +1669,6 @@ MaybeDataType TypeConstraint::asSystemlibType() const {
1669
1669
return underlyingDataType ();
1670
1670
}
1671
1671
1672
- void TypeConstraint::verifyParamFail (tv_lval val,
1673
- const Class* ctx,
1674
- const Func* func,
1675
- int paramNums) const {
1676
- verifyFail (val, ctx, func, paramNums);
1677
- assertx (
1678
- isSoft () ||
1679
- isThis () ||
1680
- (RO::EvalEnforceGenericsUB < 2 && isUpperBound ()) ||
1681
- check (val, ctx)
1682
- );
1683
- }
1684
-
1685
1672
void TypeConstraint::verifyOutParamFail (TypedValue* c,
1686
1673
const Class* ctx,
1687
1674
const Func* func,
@@ -1746,51 +1733,19 @@ void TypeConstraint::validForPropFail(const Class* declCls,
1746
1733
);
1747
1734
}
1748
1735
1749
- void TypeConstraint::verifyFail (tv_lval c, const Class* ctx, const Func* func,
1750
- int id) const {
1736
+ void TypeConstraint::verifyParamFail (tv_lval c,
1737
+ const Class* ctx,
1738
+ const Func* func,
1739
+ int id) const {
1740
+ assertx (id != ReturnId);
1751
1741
auto const tcInfo = [&] {
1752
- if (id == ReturnId) {
1753
- return folly::sformat (" return of {}()" , func->fullName ());
1754
- } else {
1755
- return folly::sformat (" argument {} passed to {}()" , id+1 , func->fullName ());
1756
- }
1742
+ return folly::sformat (" argument {} passed to {}()" , id+1 , func->fullName ());
1757
1743
};
1758
1744
if (tryCommonCoercions (c, ctx, nullptr , tcInfo)) return ;
1759
1745
1760
1746
std::string name = displayName (func->cls ());
1761
1747
auto const givenType = describe_actual_type (c);
1762
1748
1763
- // Handle return type constraint failures
1764
- if (id == ReturnId) {
1765
- std::string msg;
1766
- if (func->isClosureBody ()) {
1767
- msg =
1768
- folly::format (
1769
- " Value returned from {}closure must be of type {}, {} given" ,
1770
- func->isAsync () ? " async " : " " ,
1771
- name,
1772
- givenType
1773
- ).str ();
1774
- } else {
1775
- msg =
1776
- folly::format (
1777
- " Value returned from {}{} {}() must be {} {}, {} given" ,
1778
- func->isAsync () ? " async " : " " ,
1779
- func->preClass () ? " method" : " function" ,
1780
- func->fullName (),
1781
- isUpperBound () ? " upper-bounded by" : " of type" ,
1782
- name,
1783
- givenType
1784
- ).str ();
1785
- }
1786
- if (!isSoft () && (!isUpperBound () || RuntimeOption::EvalEnforceGenericsUB >= 2 )) {
1787
- raise_return_typehint_error (msg);
1788
- } else {
1789
- raise_warning_unsampled (msg);
1790
- }
1791
- return ;
1792
- }
1793
-
1794
1749
// Handle parameter type constraint failures
1795
1750
if (isExtended () &&
1796
1751
(isSoft () ||
@@ -1844,6 +1799,51 @@ void TypeConstraint::verifyFail(tv_lval c, const Class* ctx, const Func* func,
1844
1799
}
1845
1800
}
1846
1801
}
1802
+
1803
+ assertx (
1804
+ isSoft () ||
1805
+ isThis () ||
1806
+ (RO::EvalEnforceGenericsUB < 2 && isUpperBound ()) ||
1807
+ check (c, ctx)
1808
+ );
1809
+ }
1810
+
1811
+ void TypeConstraint::verifyReturnFail (tv_lval c, const Class* ctx,
1812
+ const Func* func) const {
1813
+ auto const tcInfo = [&] {
1814
+ return folly::sformat (" return of {}()" , func->fullName ());
1815
+ };
1816
+ if (tryCommonCoercions (c, ctx, nullptr , tcInfo)) return ;
1817
+
1818
+ std::string name = displayName (func->cls ());
1819
+ auto const givenType = describe_actual_type (c);
1820
+
1821
+ std::string msg;
1822
+ if (func->isClosureBody ()) {
1823
+ msg =
1824
+ folly::format (
1825
+ " Value returned from {}closure must be of type {}, {} given" ,
1826
+ func->isAsync () ? " async " : " " ,
1827
+ name,
1828
+ givenType
1829
+ ).str ();
1830
+ } else {
1831
+ msg =
1832
+ folly::format (
1833
+ " Value returned from {}{} {}() must be {} {}, {} given" ,
1834
+ func->isAsync () ? " async " : " " ,
1835
+ func->preClass () ? " method" : " function" ,
1836
+ func->fullName (),
1837
+ isUpperBound () ? " upper-bounded by" : " of type" ,
1838
+ name,
1839
+ givenType
1840
+ ).str ();
1841
+ }
1842
+ if (!isSoft () && (!isUpperBound () || RuntimeOption::EvalEnforceGenericsUB >= 2 )) {
1843
+ raise_return_typehint_error (msg);
1844
+ } else {
1845
+ raise_warning_unsampled (msg);
1846
+ }
1847
1847
}
1848
1848
1849
1849
// ////////////////////////////////////////////////////////////////////
0 commit comments