Skip to content

Commit

Permalink
PHP7 - Fix php7 weak vs strict types
Browse files Browse the repository at this point in the history
Summary: Closes #7198

Reviewed By: paulbiss

Differential Revision: D4201632

fbshipit-source-id: ca1e253131158c406bf328d2a0dcaa833ac597a4
  • Loading branch information
mofarrell authored and hhvm-bot committed Jun 1, 2017
1 parent 689cd6b commit f02a287
Show file tree
Hide file tree
Showing 38 changed files with 989 additions and 197 deletions.
61 changes: 30 additions & 31 deletions hphp/parser/hphp.5.tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ static const yytype_uint16 yyrline[] =
3372, 3376, 3377, 3381, 3382, 3386, 3387, 3390, 3395, 3396,
3400, 3403, 3405, 3409, 3415, 3416, 3417, 3421, 3425, 3433,
3438, 3450, 3452, 3456, 3459, 3461, 3466, 3471, 3477, 3480,
3485, 3490, 3492, 3499, 3502, 3505, 3506, 3509, 3512, 3513,
3518, 3520, 3524, 3530, 3540, 3541
3485, 3490, 3492, 3499, 3501, 3504, 3505, 3508, 3511, 3512,
3517, 3519, 3523, 3529, 3539, 3540
};
#endif

Expand Down Expand Up @@ -13164,105 +13164,104 @@ YYLTYPE yylloc = yyloc_default;

case 1063:
#line 3499 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeSpecialization((yyvsp[0]), '?');
{ _p->onTypeSpecialization((yyvsp[0]), '?');
(yyval) = (yyvsp[0]); }
#line 13169 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13168 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1064:
#line 3502 "hphp.y" /* yacc.c:1646 */
#line 3501 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeSpecialization((yyvsp[0]), '@');
(yyval) = (yyvsp[0]); }
#line 13177 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13176 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1065:
#line 3505 "hphp.y" /* yacc.c:1646 */
#line 3504 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13183 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13182 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1066:
#line 3506 "hphp.y" /* yacc.c:1646 */
#line 3505 "hphp.y" /* yacc.c:1646 */
{ Token t; t.reset();
(yyvsp[0]).setText("array");
_p->onTypeAnnotation((yyval), (yyvsp[0]), t); }
#line 13191 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13190 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1067:
#line 3509 "hphp.y" /* yacc.c:1646 */
#line 3508 "hphp.y" /* yacc.c:1646 */
{ Token t; t.reset();
(yyvsp[0]).setText("callable");
_p->onTypeAnnotation((yyval), (yyvsp[0]), t); }
#line 13199 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13198 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1068:
#line 3512 "hphp.y" /* yacc.c:1646 */
#line 3511 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13205 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13204 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1069:
#line 3515 "hphp.y" /* yacc.c:1646 */
#line 3514 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeAnnotation((yyval), (yyvsp[-2]), (yyvsp[0]));
_p->onTypeSpecialization((yyval), 'a'); }
#line 13213 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13212 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1070:
#line 3518 "hphp.y" /* yacc.c:1646 */
#line 3517 "hphp.y" /* yacc.c:1646 */
{ (yyvsp[-1]).setText("array");
_p->onTypeAnnotation((yyval), (yyvsp[-1]), (yyvsp[0])); }
#line 13220 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13219 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1071:
#line 3520 "hphp.y" /* yacc.c:1646 */
#line 3519 "hphp.y" /* yacc.c:1646 */
{ (yyvsp[0]).xhpLabel();
Token t; t.reset();
_p->onTypeAnnotation((yyval), (yyvsp[0]), t);
_p->onTypeSpecialization((yyval), 'x'); }
#line 13229 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13228 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1072:
#line 3526 "hphp.y" /* yacc.c:1646 */
#line 3525 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeList((yyvsp[-1]), (yyvsp[-4]));
_p->onTypeAnnotation((yyval), (yyvsp[-6]), (yyvsp[-1]));
_p->onTypeSpecialization((yyval), 'f'); }
#line 13238 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13237 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1073:
#line 3532 "hphp.y" /* yacc.c:1646 */
#line 3531 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeList((yyvsp[-4]), (yyvsp[-2]));
Token t; t.reset(); t.setText("array");
_p->onTypeAnnotation((yyval), t, (yyvsp[-4]));
_p->onTypeSpecialization((yyval), 't'); }
#line 13248 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13247 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1074:
#line 3540 "hphp.y" /* yacc.c:1646 */
#line 3539 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13254 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13253 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;

case 1075:
#line 3541 "hphp.y" /* yacc.c:1646 */
#line 3540 "hphp.y" /* yacc.c:1646 */
{ (yyval).reset(); }
#line 13260 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13259 "hphp.5.tab.cpp" /* yacc.c:1646 */
break;


#line 13264 "hphp.5.tab.cpp" /* yacc.c:1646 */
#line 13263 "hphp.5.tab.cpp" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
Expand Down Expand Up @@ -13498,7 +13497,7 @@ YYLTYPE yylloc = yyloc_default;
#endif
return yyresult;
}
#line 3544 "hphp.y" /* yacc.c:1906 */
#line 3543 "hphp.y" /* yacc.c:1906 */

/* !PHP5_ONLY*/
bool Parser::parseImpl5() {
Expand Down
61 changes: 30 additions & 31 deletions hphp/parser/hphp.7.tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ static const yytype_uint16 yyrline[] =
3376, 3377, 3381, 3382, 3386, 3387, 3390, 3395, 3396, 3400,
3403, 3405, 3409, 3415, 3416, 3417, 3421, 3425, 3433, 3438,
3450, 3452, 3456, 3459, 3461, 3466, 3471, 3477, 3480, 3485,
3490, 3492, 3499, 3502, 3505, 3506, 3509, 3512, 3513, 3518,
3520, 3524, 3530, 3540, 3541
3490, 3492, 3499, 3501, 3504, 3505, 3508, 3511, 3512, 3517,
3519, 3523, 3529, 3539, 3540
};
#endif

Expand Down Expand Up @@ -13131,105 +13131,104 @@ YYLTYPE yylloc = yyloc_default;

case 1062:
#line 3499 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeSpecialization((yyvsp[0]), '?');
{ _p->onTypeSpecialization((yyvsp[0]), '?');
(yyval) = (yyvsp[0]); }
#line 13136 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13135 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1063:
#line 3502 "hphp.y" /* yacc.c:1646 */
#line 3501 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeSpecialization((yyvsp[0]), '@');
(yyval) = (yyvsp[0]); }
#line 13144 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13143 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1064:
#line 3505 "hphp.y" /* yacc.c:1646 */
#line 3504 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13150 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13149 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1065:
#line 3506 "hphp.y" /* yacc.c:1646 */
#line 3505 "hphp.y" /* yacc.c:1646 */
{ Token t; t.reset();
(yyvsp[0]).setText("array");
_p->onTypeAnnotation((yyval), (yyvsp[0]), t); }
#line 13158 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13157 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1066:
#line 3509 "hphp.y" /* yacc.c:1646 */
#line 3508 "hphp.y" /* yacc.c:1646 */
{ Token t; t.reset();
(yyvsp[0]).setText("callable");
_p->onTypeAnnotation((yyval), (yyvsp[0]), t); }
#line 13166 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13165 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1067:
#line 3512 "hphp.y" /* yacc.c:1646 */
#line 3511 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13172 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13171 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1068:
#line 3515 "hphp.y" /* yacc.c:1646 */
#line 3514 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeAnnotation((yyval), (yyvsp[-2]), (yyvsp[0]));
_p->onTypeSpecialization((yyval), 'a'); }
#line 13180 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13179 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1069:
#line 3518 "hphp.y" /* yacc.c:1646 */
#line 3517 "hphp.y" /* yacc.c:1646 */
{ (yyvsp[-1]).setText("array");
_p->onTypeAnnotation((yyval), (yyvsp[-1]), (yyvsp[0])); }
#line 13187 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13186 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1070:
#line 3520 "hphp.y" /* yacc.c:1646 */
#line 3519 "hphp.y" /* yacc.c:1646 */
{ (yyvsp[0]).xhpLabel();
Token t; t.reset();
_p->onTypeAnnotation((yyval), (yyvsp[0]), t);
_p->onTypeSpecialization((yyval), 'x'); }
#line 13196 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13195 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1071:
#line 3526 "hphp.y" /* yacc.c:1646 */
#line 3525 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeList((yyvsp[-1]), (yyvsp[-4]));
_p->onTypeAnnotation((yyval), (yyvsp[-6]), (yyvsp[-1]));
_p->onTypeSpecialization((yyval), 'f'); }
#line 13205 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13204 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1072:
#line 3532 "hphp.y" /* yacc.c:1646 */
#line 3531 "hphp.y" /* yacc.c:1646 */
{ only_in_hh_syntax(_p);
_p->onTypeList((yyvsp[-4]), (yyvsp[-2]));
Token t; t.reset(); t.setText("array");
_p->onTypeAnnotation((yyval), t, (yyvsp[-4]));
_p->onTypeSpecialization((yyval), 't'); }
#line 13215 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13214 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1073:
#line 3540 "hphp.y" /* yacc.c:1646 */
#line 3539 "hphp.y" /* yacc.c:1646 */
{ (yyval) = (yyvsp[0]); }
#line 13221 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13220 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;

case 1074:
#line 3541 "hphp.y" /* yacc.c:1646 */
#line 3540 "hphp.y" /* yacc.c:1646 */
{ (yyval).reset(); }
#line 13227 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13226 "hphp.7.tab.cpp" /* yacc.c:1646 */
break;


#line 13231 "hphp.7.tab.cpp" /* yacc.c:1646 */
#line 13230 "hphp.7.tab.cpp" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
Expand Down Expand Up @@ -13465,7 +13464,7 @@ YYLTYPE yylloc = yyloc_default;
#endif
return yyresult;
}
#line 3544 "hphp.y" /* yacc.c:1906 */
#line 3543 "hphp.y" /* yacc.c:1906 */

/* !PHP5_ONLY*/
/* REMOVED */
Expand Down
3 changes: 1 addition & 2 deletions hphp/parser/hphp.y
Original file line number Diff line number Diff line change
Expand Up @@ -3496,8 +3496,7 @@ array_typelist:
hh_type:
/* double-optional types will be rejected by the typechecker; we
* already allow plenty of nonsense types anyway */
'?' hh_type { only_in_hh_syntax(_p);
_p->onTypeSpecialization($2, '?');
'?' hh_type { _p->onTypeSpecialization($2, '?');
$$ = $2; }
| '@' hh_type { only_in_hh_syntax(_p);
_p->onTypeSpecialization($2, '@');
Expand Down
55 changes: 2 additions & 53 deletions hphp/runtime/base/actrec-args.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ getArg(ActRec *ar, unsigned arg) {
raise_warning("Required parameter %d not passed", (int)arg);
return 0L;
}
if (!tvCoerceParamInPlace(tv, DType)) {
if (!tvCoerceParamInPlace(tv, DType, ar->func()->isBuiltin())) {
raise_param_type_warning(ar->func()->displayName()->data(),
arg + 1, DType, tv->m_type);
tvCastInPlace(tv, DType);
Expand All @@ -109,7 +109,7 @@ getArg(ActRec *ar, unsigned arg,
if (!tv) {
return def;
}
if (!tvCoerceParamInPlace(tv, DType)) {
if (!tvCoerceParamInPlace(tv, DType, ar->func()->isBuiltin())) {
raise_param_type_warning(ar->func()->displayName()->data(),
arg + 1, DType, tv->m_type);
tvCastInPlace(tv, DType);
Expand All @@ -119,57 +119,6 @@ getArg(ActRec *ar, unsigned arg,

struct IncoercibleArgumentException : Exception {};

/**
* Get numbered arg (zero based) and return data (coerce if needed)
*
* e.g.: double dval = getArg<KindOfDouble>(ar, 0);
*
* Raise warning and throw IncoercibleArgumentException if argument
* is not provided/not coercible
*/
template <DataType DType>
typename std::enable_if<DType != KindOfRef,
typename DataTypeCPPType<DType>::type>::type
getArgStrict(ActRec *ar, unsigned arg) {
auto tv = getArg(ar, arg);
if (!tv) {
raise_warning("Required parameter %d not passed", (int)arg);
throw IncoercibleArgumentException();
}
if (!tvCoerceParamInPlace(tv, DType)) {
raise_param_type_warning(ar->func()->displayName()->data(),
arg + 1, DType, tv->m_type);
throw IncoercibleArgumentException();
}
return unpack_tv<DType>(tv);
}

/**
* Get numbered arg (zero based) and return data (coerce if needed)
*
* e.g. int64_t lval = getArg<KindOfInt64>(ar, 1, 42);
*
* Raise warning and throw IncoercibleArgumentException if argument
* is not coercible
*
* Returns default value (42 in example) if arg not passed
*/
template <DataType DType>
typename DataTypeCPPType<DType>::type
getArgStrict(ActRec *ar, unsigned arg,
typename DataTypeCPPType<DType>::type def) {
TypedValue *tv = getArg(ar, arg);
if (!tv) {
return def;
}
if (!tvCoerceParamInPlace(tv, DType)) {
raise_param_type_warning(ar->func()->displayName()->data(),
arg + 1, DType, tv->m_type);
throw IncoercibleArgumentException();
}
return unpack_tv<DType>(tv);
}

/////////////////////////////////////////////////////////////////////////////
} // namespace HPHP
#endif // incl_HPHP_ACTREC_ARGS_H
Loading

0 comments on commit f02a287

Please sign in to comment.