Infer void for statement-less function bodies in isolatedDeclarations syntactic inference#4418
Open
weswigham wants to merge 1 commit into
Open
Infer void for statement-less function bodies in isolatedDeclarations syntactic inference#4418weswigham wants to merge 1 commit into
isolatedDeclarations syntactic inference#4418weswigham wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the isolatedDeclarations syntactic inference path to treat statement-less (empty) function bodies as returning void, aligning with the checker’s behavior and reducing spurious “explicit return type required” diagnostics for empty/no-op functions.
Changes:
- Added a
voidpseudo-type (PseudoTypeKindVoid/PseudoTypeVoid) and mapped it through the node/type builders. - Updated pseudo-checker return-type inference to return
voidfor empty block bodies. - Refreshed a large set of isolated-declarations diagnostic baselines to reflect the new inference behavior (notably removing TS9007 in these cases).
- Updated the fourslash “known failing tests” list to include additional failures.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/pseudochecker/type.go | Adds a new PseudoTypeKindVoid and PseudoTypeVoid singleton. |
| internal/pseudochecker/lookup.go | Returns PseudoTypeVoid for empty block-bodied functions during single-return inference. |
| internal/checker/pseudotypenodebuilder.go | Maps PseudoTypeKindVoid to void type nodes and to the checker’s voidType. |
| internal/fourslash/_scripts/failingTests.txt | Adds newly failing code-fix fourslash tests to the skip list. |
| testdata/baselines/reference/submoduleTriaged/compiler/isolatedDeclarationErrorsReturnTypes.errors.txt.diff | Baseline updates reflecting changed isolated-declarations diagnostics (TS9007→other outcomes). |
| testdata/baselines/reference/submoduleTriaged/compiler/isolatedDeclarationErrorsExpandoFunctions.errors.txt.diff | Baseline updates reflecting changed diagnostics for expando-function scenarios. |
| testdata/baselines/reference/submoduleTriaged/compiler/isolatedDeclarationErrorsClasses.errors.txt.diff | Baseline updates removing method-return-type requirements in some empty-body cases. |
| testdata/baselines/reference/submoduleTriaged/compiler/isolatedDeclarationErrors.errors.txt.diff | Baseline updates reflecting fewer TS9007 diagnostics for empty functions. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt.diff | Baseline diff updates reflecting removed TS9007 for empty exported function. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt | Baseline updates reflecting removed TS9007 for empty exported function. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsReturnTypes.errors.txt | Baseline updates reflecting new diagnostic set in return-type-related fixtures. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff | Baseline diff updates reflecting removed TS9008 for empty methods in object literals. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt | Baseline updates reflecting removed TS9008 for empty methods in object literals. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsFunctionDeclarations.errors.txt.diff | Baseline diff updates reflecting removed TS9007 for empty exported function decl. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsFunctionDeclarations.errors.txt | Baseline updates reflecting removed TS9007 for empty exported function decl. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.errors.txt | Baseline updates reflecting removed TS9007 for the top-level empty exported function. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsClasses.errors.txt | Baseline updates reflecting removed TS9008 for empty method bodies in classes. |
| testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.errors.txt | Baseline updates reflecting removed TS9007 for const x = () => {}-style empty functions. |
Comment on lines
227
to
232
| body := fn.Body() | ||
| if ast.IsBlock(body) { | ||
| if len(body.Statements()) == 0 { | ||
| return PseudoTypeVoid | ||
| } | ||
| ast.ForEachReturnStatement(body, func(stmt *ast.Node) bool { |
Comment on lines
64
to
+66
| TestCodeFixMissingTypeAnnotationOnExports11 | ||
| TestCodeFixMissingTypeAnnotationOnExports16 | ||
| TestCodeFixMissingTypeAnnotationOnExports22_formatting |
Comment on lines
70
to
+73
| TestCodeFixMissingTypeAnnotationOnExports28_long_types | ||
| TestCodeFixMissingTypeAnnotationOnExports33_methods | ||
| TestCodeFixMissingTypeAnnotationOnExports43_expando_functions_2 | ||
| TestCodeFixMissingTypeAnnotationOnExports46_decorators_experimental |
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.
Per discussion in today's design meeting, pending any objections from the community. Since we no longer infer
anyfor statementless function bodies in JS, we always, uniformly, infervoidfor these in the checker - making it a no-brainer to do the inference syntactically and avoid anisolatedDeclarationserror requiring an explicit: voidin the common case of an empty/noop function/method.We'll move this to the 7.1 milestone once we have one~