Conversation
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64467
Context
I'm building syscript, a compiler that compiles TypeScript syntax to C for systems
programming. It uses the TypeScript 7 API to type-check the program and then walks
every node, requesting its type in a batch with
getTypeAtLocation. That walk crashedthe API server on the first file that used
import type.Problem
checker.GetTypeAtLocationpanics with a nil pointer dereference when called on theImportClauseof a type-only import without a default binding:It reproduces with the latest nightly (
typescript@7.1.0-dev.20260926.1).Cause
ast.IsTypeDeclarationreturns true for a type-onlyImportClause, sogetTypeOfNodetakes the type-declaration branch and passes the result of
getSymbolOfDeclarationstraight to
getDeclaredTypeOfSymbol. An import clause only has a symbol when it hasa default binding (
import type X from "..."), so forimport type { U }andimport type * as nsthe symbol is nil.The missing check looks historical rather than intentional. When this branch was
written,
isTypeDeclarationonly covered type parameters, classes, interfaces, typealiases and enums, which always have a symbol. #35200 (type-only imports and exports)
added
ImportClause,ImportSpecifierandExportSpecifier; the specifiers alwayshave a symbol, but a clause without a default binding does not. The same unguarded
branch is still in Strada's
getTypeOfNode, and this code was ported from it.Fix
Return
errorTypewhen the declaration has no symbol, matching the neighboringIsTypeDeclarationNameandIsDeclarationbranches, which already guard against a nilsymbol.
This also makes type-only clauses consistent with regular ones: a regular
import { U } from "./types"clause is not a type declaration, so it already reachesthe
IsDeclarationbranch and getserrorTypethere.Tests
Added
TestGetTypeAtLocationOfTypeOnlyImportClauseininternal/checker. It requeststhe type of a named and a namespace type-only import clause and checks that both match
the type of an equivalent regular import clause. It panics without the fix and passes
with it.
Ran the pre-submission checklist from CONTRIBUTING.md. Everything passes except
internal/vfs/osvfsTestOS/Realpath, which also fails onmainin my environmentbecause my home directory is a symlink (
/home→/var/home, Fedora Atomic).I used Claude Code for this change; I've reviewed it and will handle the review.