Fix(50161): Instantiation expressions trigger incorrect error messages (#52373)

This commit is contained in:
navya9singh
2023-01-31 11:15:10 -08:00
committed by GitHub
parent 7c220232f2
commit c93f20bcf8
9 changed files with 286 additions and 15 deletions

View File

@@ -44708,7 +44708,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return node.parent.kind === SyntaxKind.TypeReference;
}
function isHeritageClauseElementIdentifier(node: Node): boolean {
function isInNameOfExpressionWithTypeArguments(node: Node): boolean {
while (node.parent.kind === SyntaxKind.PropertyAccessExpression) {
node = node.parent;
}
@@ -44834,11 +44834,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
name = name.parent as QualifiedName | PropertyAccessEntityNameExpression | JSDocMemberName;
}
if (isHeritageClauseElementIdentifier(name)) {
if (isInNameOfExpressionWithTypeArguments(name)) {
let meaning = SymbolFlags.None;
// In an interface or class, we're definitely interested in a type.
if (name.parent.kind === SyntaxKind.ExpressionWithTypeArguments) {
meaning = SymbolFlags.Type;
// An 'ExpressionWithTypeArguments' may appear in type space (interface Foo extends Bar<T>),
// value space (return foo<T>), or both(class Foo extends Bar<T>); ensure the meaning matches.
meaning = isPartOfTypeNode(name) ? SymbolFlags.Type : SymbolFlags.Value;
// In a class 'extends' clause we are also looking for a value.
if (isExpressionWithTypeArgumentsInClassExtendsClause(name.parent)) {

View File

@@ -190,3 +190,4 @@ import "./unittests/tsserver/typingsInstaller";
import "./unittests/tsserver/versionCache";
import "./unittests/tsserver/watchEnvironment";
import "./unittests/debugDeprecation";
import "./unittests/tsserver/inconsistentErrorInEditor";

View File

@@ -0,0 +1,41 @@
import * as ts from "../../_namespaces/ts";
import {
createServerHost,
} from "../virtualFileSystemWithWatch";
import {
baselineTsserverLogs,
createLoggerWithInMemoryLogs,
createSession,
verifyGetErrRequest,
} from "./helpers";
describe("unittests:: tsserver:: inconsistentErrorInEditor", () => {
it("should not error", () => {
const host = createServerHost([]);
const session = createSession(host, { canUseEvents: true, noGetErrOnBackgroundUpdate: true, logger: createLoggerWithInMemoryLogs(host) });
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
command: ts.server.protocol.CommandTypes.UpdateOpen,
arguments: {
changedFiles: [],
closedFiles: [],
openFiles: [
{
file: "^/untitled/ts-nul-authority/Untitled-1",
fileContent: "export function foo<U>() {\r\n /*$*/return bar<U>;\r\n}\r\n\r\nexport function bar<T>(x: T) {\r\n return x;\r\n}\r\n\r\nlet x = foo()(42);",
scriptKindName: "TS"
}
]
}
});
session.executeCommandSeq<ts.server.protocol.EncodedSemanticClassificationsRequest>({
command: ts.server.protocol.CommandTypes.EncodedSemanticClassificationsFull,
arguments: {
file: "^/untitled/ts-nul-authority/Untitled-1",
start: 0,
length: 128,
format: "2020"
}
});
verifyGetErrRequest({ session, host, files: ["^/untitled/ts-nul-authority/Untitled-1"] });
baselineTsserverLogs("inconsistentErrorInEditor", "should not error", session);
});
});