Skip to content

Commit

Permalink
Add related span to original declaration on disagreeing variable/prop…
Browse files Browse the repository at this point in the history
…erty types.
  • Loading branch information
DanielRosenwasser committed May 21, 2019
1 parent c71423e commit 3f59129
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/compiler/checker.ts
Expand Up @@ -5352,7 +5352,7 @@ namespace ts {
return type;
}
else if (declaredType !== errorType && type !== errorType && !isTypeIdenticalTo(declaredType, type)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(declaredType, declaration, type);
errorNextVariableOrPropertyDeclarationMustHaveSameType(/*firstDeclaration*/ undefined, declaredType, declaration, type);
}
}
return declaredType;
Expand Down Expand Up @@ -26839,7 +26839,7 @@ namespace ts {
if (type !== errorType && declarationType !== errorType &&
!isTypeIdenticalTo(type, declarationType) &&
!(symbol.flags & SymbolFlags.Assignment)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(type, node, declarationType);
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType);
}
if (node.initializer) {
checkTypeAssignableToAndOptionallyElaborate(checkExpressionCached(node.initializer), declarationType, node, node.initializer, /*headMessage*/ undefined);
Expand All @@ -26859,17 +26859,24 @@ namespace ts {
}
}

function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration | undefined, firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
const message = nextDeclaration.kind === SyntaxKind.PropertyDeclaration || nextDeclaration.kind === SyntaxKind.PropertySignature
? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2
: Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2;
error(
const declName = declarationNameToString(nextDeclarationName);
const err = error(
nextDeclarationName,
message,
declarationNameToString(nextDeclarationName),
declName,
typeToString(firstType),
typeToString(nextType));
typeToString(nextType)
);
if (firstDeclaration) {
addRelatedInfo(err,
createDiagnosticForNode(firstDeclaration, Diagnostics._0_was_also_declared_here, declName)
);
}
}

function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {
Expand Down

0 comments on commit 3f59129

Please sign in to comment.