Update baselines, except JSX

JSX is still broken
This commit is contained in:
Nathan Shively-Sanders
2019-06-25 13:16:34 -07:00
parent ecfa902ba1
commit f20f700025
11 changed files with 250 additions and 182 deletions
+74 -87
View File
@@ -11659,7 +11659,7 @@ namespace ts {
return isTypeComparableTo(type1, type2) || isTypeComparableTo(type2, type1);
}
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, errorOutputObject?: { error?: Diagnostic }): boolean {
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, errorOutputObject?: { errors?: Diagnostic[] }): boolean {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain, errorOutputObject);
}
@@ -11679,10 +11679,10 @@ namespace ts {
expr: Expression | undefined,
headMessage: DiagnosticMessage | undefined,
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
): boolean {
if (isTypeRelatedTo(source, target, relation)) return true;
if (!errorNode || !elaborateError(expr, source, target, relation, headMessage, errorOutputContainer)) {
if (!errorNode || !elaborateError(expr, source, target, relation, headMessage, containingMessageChain, errorOutputContainer)) {
return checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer);
}
return false;
@@ -11698,34 +11698,35 @@ namespace ts {
target: Type,
relation: Map<RelationComparisonResult>,
headMessage: DiagnosticMessage | undefined,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
): boolean {
// TODO: The first case probably still needs to set errorOutputContainer.error to something
// TODO: Make sure all error logging in dynamic scope sets errorOutputContainer.error instead
if (!node || isOrHasGenericConditional(target)) return false;
if (!checkTypeRelatedTo(source, target, relation, /*errorNode*/ undefined)
&& elaborateDidYouMeanToCallOrConstruct(node, source, target, relation, headMessage, errorOutputContainer)) {
&& elaborateDidYouMeanToCallOrConstruct(node, source, target, relation, headMessage, containingMessageChain, errorOutputContainer)) {
return true;
}
switch (node.kind) {
case SyntaxKind.JsxExpression:
case SyntaxKind.ParenthesizedExpression:
return elaborateError((node as ParenthesizedExpression | JsxExpression).expression, source, target, relation, headMessage, errorOutputContainer);
return elaborateError((node as ParenthesizedExpression | JsxExpression).expression, source, target, relation, headMessage, containingMessageChain, errorOutputContainer);
case SyntaxKind.BinaryExpression:
switch ((node as BinaryExpression).operatorToken.kind) {
case SyntaxKind.EqualsToken:
case SyntaxKind.CommaToken:
return elaborateError((node as BinaryExpression).right, source, target, relation, headMessage, errorOutputContainer);
return elaborateError((node as BinaryExpression).right, source, target, relation, headMessage, containingMessageChain, errorOutputContainer);
}
break;
case SyntaxKind.ObjectLiteralExpression:
return elaborateObjectLiteral(node as ObjectLiteralExpression, source, target, relation, errorOutputContainer);
return elaborateObjectLiteral(node as ObjectLiteralExpression, source, target, relation, containingMessageChain, errorOutputContainer);
case SyntaxKind.ArrayLiteralExpression:
return elaborateArrayLiteral(node as ArrayLiteralExpression, source, target, relation, errorOutputContainer);
return elaborateArrayLiteral(node as ArrayLiteralExpression, source, target, relation, containingMessageChain, errorOutputContainer);
case SyntaxKind.JsxAttributes:
return elaborateJsxComponents(node as JsxAttributes, source, target, relation, errorOutputContainer);
return elaborateJsxComponents(node as JsxAttributes, source, target, relation, containingMessageChain, errorOutputContainer);
case SyntaxKind.ArrowFunction:
return elaborateArrowFunction(node as ArrowFunction, source, target, relation, errorOutputContainer);
return elaborateArrowFunction(node as ArrowFunction, source, target, relation, containingMessageChain, errorOutputContainer);
}
return false;
}
@@ -11736,7 +11737,8 @@ namespace ts {
target: Type,
relation: Map<RelationComparisonResult>,
headMessage: DiagnosticMessage | undefined,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
): boolean {
const callSignatures = getSignaturesOfType(source, SignatureKind.Call);
const constructSignatures = getSignaturesOfType(source, SignatureKind.Construct);
@@ -11745,9 +11747,9 @@ namespace ts {
const returnType = getReturnTypeOfSignature(s);
return !(returnType.flags & (TypeFlags.Any | TypeFlags.Never)) && checkTypeRelatedTo(returnType, target, relation, /*errorNode*/ undefined);
})) {
const resultObj: { error?: Diagnostic } = errorOutputContainer || {};
checkTypeAssignableTo(source, target, node, headMessage, /*containingChain*/ undefined, resultObj);
const diagnostic = resultObj.error!;
const resultObj: { errors?: Diagnostic[] } = errorOutputContainer || {};
checkTypeAssignableTo(source, target, node, headMessage, containingMessageChain, resultObj);
const diagnostic = resultObj.errors![resultObj.errors!.length - 1];
addRelatedInfo(diagnostic, createDiagnosticForNode(
node,
signatures === constructSignatures ? Diagnostics.Did_you_mean_to_use_new_with_this_expression : Diagnostics.Did_you_mean_to_call_this_expression
@@ -11763,7 +11765,8 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
): boolean {
// Don't elaborate blocks
if (isBlock(node.body)) {
@@ -11785,15 +11788,15 @@ namespace ts {
const sourceReturn = getReturnTypeOfSignature(sourceSig);
const targetReturn = getUnionType(map(targetSignatures, getReturnTypeOfSignature));
if (!checkTypeRelatedTo(sourceReturn, targetReturn, relation, /*errorNode*/ undefined)) {
const elaborated = returnExpression && elaborateError(returnExpression, sourceReturn, targetReturn, relation, /*headMessage*/ undefined, errorOutputContainer);
const elaborated = returnExpression && elaborateError(returnExpression, sourceReturn, targetReturn, relation, /*headMessage*/ undefined, containingMessageChain, errorOutputContainer);
if (elaborated) {
return elaborated;
}
const resultObj: { error?: Diagnostic } = errorOutputContainer || {};
checkTypeRelatedTo(sourceReturn, targetReturn, relation, returnExpression, /*message*/ undefined, /*chain*/ undefined, resultObj);
if (resultObj.error) {
const resultObj: { errors?: Diagnostic[] } = errorOutputContainer || {};
checkTypeRelatedTo(sourceReturn, targetReturn, relation, returnExpression, /*message*/ undefined, containingMessageChain, resultObj);
if (resultObj.errors) {
if (target.symbol && length(target.symbol.declarations)) {
addRelatedInfo(resultObj.error, createDiagnosticForNode(
addRelatedInfo(resultObj.errors[resultObj.errors.length - 1], createDiagnosticForNode(
target.symbol.declarations[0],
Diagnostics.The_expected_type_comes_from_the_return_type_of_this_signature,
));
@@ -11815,7 +11818,8 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
// Assignability failure - check each prop individually, and if that fails, fall back on the bad error span
let reportedError = false;
@@ -11825,22 +11829,22 @@ namespace ts {
if (!targetPropType || targetPropType.flags & TypeFlags.IndexedAccess) continue; // Don't elaborate on indexes on generic variables
const sourcePropType = getIndexedAccessTypeOrUndefined(source, nameType);
if (sourcePropType && !checkTypeRelatedTo(sourcePropType, targetPropType, relation, /*errorNode*/ undefined)) {
const elaborated = next && elaborateError(next, sourcePropType, targetPropType, relation, /*headMessage*/ undefined, errorOutputContainer);
const elaborated = next && elaborateError(next, sourcePropType, targetPropType, relation, /*headMessage*/ undefined, containingMessageChain, errorOutputContainer);
if (elaborated) {
reportedError = true;
}
else {
// Issue error on the prop itself, since the prop couldn't elaborate the error
const resultObj: { error?: Diagnostic } = errorOutputContainer || {};
const resultObj: { errors?: Diagnostic[] } = errorOutputContainer || {};
// Use the expression type, if available
const specificSource = next ? checkExpressionForMutableLocation(next, CheckMode.Normal, sourcePropType) : sourcePropType;
const result = checkTypeRelatedTo(specificSource, targetPropType, relation, prop, errorMessage, /*containingChain*/ undefined, resultObj);
const result = checkTypeRelatedTo(specificSource, targetPropType, relation, prop, errorMessage, containingMessageChain, resultObj);
if (result && specificSource !== sourcePropType) {
// If for whatever reason the expression type doesn't yield an error, make sure we still issue an error on the sourcePropType
checkTypeRelatedTo(sourcePropType, targetPropType, relation, prop, errorMessage, /*containingChain*/ undefined, resultObj);
checkTypeRelatedTo(sourcePropType, targetPropType, relation, prop, errorMessage, containingMessageChain, resultObj);
}
if (resultObj.error) {
const reportedDiag = resultObj.error;
if (resultObj.errors) {
const reportedDiag = resultObj.errors[resultObj.errors.length - 1];
const propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
const targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
@@ -11928,9 +11932,10 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
let result = elaborateElementwise(generateJsxAttributes(node), source, target, relation, errorOutputContainer);
let result = elaborateElementwise(generateJsxAttributes(node), source, target, relation, containingMessageChain, errorOutputContainer);
let invalidTextDiagnostic: DiagnosticMessage | undefined;
if (isJsxOpeningElement(node.parent) && isJsxElement(node.parent.parent)) {
const containingElement = node.parent.parent;
@@ -11949,7 +11954,7 @@ namespace ts {
if (arrayLikeTargetParts !== neverType) {
const realSource = createTupleType(checkJsxChildren(containingElement, CheckMode.Normal));
const children = generateJsxChildren(containingElement, getInvalidTextualChildDiagnostic)
result = elaborateElementwise(children, realSource, arrayLikeTargetParts, relation, errorOutputContainer) || result;
result = elaborateElementwise(children, realSource, arrayLikeTargetParts, relation, containingMessageChain, errorOutputContainer) || result;
}
else if (!isTypeRelatedTo(getIndexedAccessType(source, childrenNameType), childrenTargetType, relation)) {
// arity mismatch
@@ -11961,7 +11966,7 @@ namespace ts {
typeToString(childrenTargetType)
);
if (errorOutputContainer && errorOutputContainer.skipLogging) {
errorOutputContainer.error = diag;
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
}
}
}
@@ -11975,6 +11980,7 @@ namespace ts {
source,
target,
relation,
containingMessageChain,
errorOutputContainer
) || result;
}
@@ -11989,7 +11995,7 @@ namespace ts {
typeToString(childrenTargetType)
);
if (errorOutputContainer && errorOutputContainer.skipLogging) {
errorOutputContainer.error = diag;
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
}
}
}
@@ -12027,16 +12033,17 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
if (target.flags & TypeFlags.Primitive) return false;
if (isTupleLikeType(source)) {
return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, errorOutputContainer);
return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
}
// recreate a tuple from the elements, if possible
const tupleizedType = checkArrayLiteral(node, CheckMode.Contextual, /*forceTuple*/ true);
if (isTupleLikeType(tupleizedType)) {
return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, errorOutputContainer);
return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
}
return false;
}
@@ -12070,10 +12077,11 @@ namespace ts {
source: Type,
target: Type,
relation: Map<RelationComparisonResult>,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } | undefined
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
if (target.flags & TypeFlags.Primitive) return false;
return elaborateElementwise(generateObjectLiteralElements(node), source, target, relation, errorOutputContainer);
return elaborateElementwise(generateObjectLiteralElements(node), source, target, relation, containingMessageChain, errorOutputContainer);
}
/**
@@ -12423,7 +12431,7 @@ namespace ts {
errorNode: Node | undefined,
headMessage?: DiagnosticMessage,
containingMessageChain?: () => DiagnosticMessageChain | undefined,
errorOutputContainer?: { error?: Diagnostic, skipLogging?: boolean },
errorOutputContainer?: { errors?: Diagnostic[], skipLogging?: boolean },
): boolean {
let errorInfo: DiagnosticMessageChain | undefined;
let relatedInfo: [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] | undefined;
@@ -12442,7 +12450,7 @@ namespace ts {
if (overflow) {
const diag = error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
if (errorOutputContainer) {
errorOutputContainer.error = diag;
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
}
}
else if (errorInfo) {
@@ -12471,14 +12479,14 @@ namespace ts {
addRelatedInfo(diag, ...relatedInfo);
}
if (errorOutputContainer) {
errorOutputContainer.error = diag;
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
}
if (!errorOutputContainer || !errorOutputContainer.skipLogging) {
diagnostics.add(diag);
}
}
if (errorNode && errorOutputContainer && errorOutputContainer.skipLogging && result === Ternary.False) {
Debug.assert(!!errorOutputContainer.error, "missed opportunity to interact with error.");
Debug.assert(!!errorOutputContainer.errors, "missed opportunity to interact with error.");
}
return result !== Ternary.False;
@@ -21171,7 +21179,7 @@ namespace ts {
checkMode: CheckMode,
reportErrors: boolean,
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean }
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean }
) {
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
@@ -21191,17 +21199,14 @@ namespace ts {
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
) {
const errorOutputContainer: { error?: Diagnostic, skipLogging?: boolean } = { error: undefined, skipLogging: true };
const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
if (isJsxOpeningLikeElement(node)) {
const r = checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer);
if (!r) {
if (reportErrors) {
Debug.assert(!!errorOutputContainer.error, "has error 0");
return errorOutputContainer.error;
}
else {
return true;
Debug.assert(!!errorOutputContainer.errors, "has error 0");
}
return errorOutputContainer.errors || [];
}
}
const thisType = getThisTypeOfSignature(signature);
@@ -21213,15 +21218,9 @@ namespace ts {
const thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType;
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;
const headMessage = Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1;
const r = checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer);
if (!r) {
if (reportErrors) {
Debug.assert(!!errorOutputContainer.error, "has error 1"); // CLEAR
return errorOutputContainer.error;
}
else {
return true;
}
if (!checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer)) {
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 1"); // CLEAR
return errorOutputContainer.errors || [];
}
}
const headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
@@ -21236,30 +21235,18 @@ namespace ts {
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
const r = checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, errorOutputContainer);
if (!r) {
if (reportErrors) {
Debug.assert(!!errorOutputContainer.error, "has error 2"); // CLEAR
return errorOutputContainer.error;
}
else {
return true;
}
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, errorOutputContainer)) {
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 2"); // CLEAR
return errorOutputContainer.errors || [];
}
}
}
if (restType) {
const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, /*context*/ undefined);
const errorNode = reportErrors ? argCount < args.length ? args[argCount] : node : undefined;
const r = checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, undefined, errorOutputContainer);
if (!r) {
if (reportErrors) {
Debug.assert(!!errorOutputContainer.error, "has error 3"); // CLEAR
return errorOutputContainer.error;
}
else {
return true;
}
if (!checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, undefined, errorOutputContainer)) {
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 3"); // CLEAR
return errorOutputContainer.errors || [];
}
}
return undefined;
@@ -21597,13 +21584,14 @@ namespace ts {
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
chain = chainDiagnosticMessages(chain, Diagnostics.No_suitable_overload_for_this_call);
}
const d = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
Debug.assert(!!d, "No error for last signature");
if (d) {
Debug.assert(d !== true);
const ds = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
Debug.assert(!!ds, "No error for last signature");
if (ds) {
// if elaboration already displayed the error, don't do anything extra
// note that we could do this always here, but getSignatureApplicabilityError is currently not configured to do that
diagnostics.add(d as Diagnostic);
for (const d of ds as Diagnostic[]) {
diagnostics.add(d);
}
}
}
else {
@@ -21611,12 +21599,11 @@ namespace ts {
let i = 0;
for (const c of candidatesForArgumentError) {
i++;
const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
const d = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
Debug.assert(!!d, "No error for signature (1)");
if (d) {
Debug.assert(d !== true);
related.push(d as Diagnostic);
const chain = () => chainDiagnosticMessages(undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
const ds = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, chain);
Debug.assert(!!ds, "No error for signature (1)");
if (ds) {
related.push(...ds as Diagnostic[])
}
}
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.No_suitable_overload_for_this_call), related));