Skip to content

Commit 5a448d2

Browse files
Herman Ventersgolemon
Herman Venter
authored andcommitted
Unrevert "Fix bug in way function types are serialized to the Code Model."
This is a partial unrevert of "Fix bug in way function types are serialized to the Code Model". The fix to CodeModelToPHP::visitTypeExpression() could not be restored because the CodeModelToPHP class is not built into HHVM at present. Reviewed By: @ptarjan
1 parent 07c9976 commit 5a448d2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hphp/compiler/type_annotation.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,15 @@ void TypeAnnotation::outputCodeModel(CodeGenerator& cg) {
189189
auto numProps = 1;
190190
if (m_nullable) numProps++;
191191
if (m_soft) numProps++;
192-
if (m_function) numProps++;
193-
if (numTypeArgs > 0) numProps++;
192+
if (m_function) {
193+
numProps++;
194+
// Since this is a function type, the first type argument is the return type
195+
// and no typeArguments property will be serialized unless there are at
196+
// least two type arguments.
197+
if (numTypeArgs > 1) numProps++;
198+
} else {
199+
if (numTypeArgs > 0) numProps++;
200+
}
194201
cg.printObjectHeader("TypeExpression", numProps);
195202
cg.printPropertyHeader("name");
196203
cg.printValue(m_tuple ? "tuple" : m_name);
@@ -206,6 +213,9 @@ void TypeAnnotation::outputCodeModel(CodeGenerator& cg) {
206213
cg.printPropertyHeader("returnType");
207214
typeArgsElem->outputCodeModel(cg);
208215
typeArgsElem = typeArgsElem->m_typeList;
216+
// Since we've grabbed the first element of the list as the return
217+
// type, make sure that the logic for serializing type arguments gets
218+
// disabled unless there is at least one more type argument.
209219
numTypeArgs--;
210220
}
211221
if (numTypeArgs > 0) {

0 commit comments

Comments
 (0)