Skip to content

Port "Disallow type and interface declarations in statements with blockless bodies"#1037

Merged
jakebailey merged 2 commits into
microsoft:mainfrom
Andarist:port/disallow-type-interface-inblockless-statements
Jun 4, 2025
Merged

Port "Disallow type and interface declarations in statements with blockless bodies"#1037
jakebailey merged 2 commits into
microsoft:mainfrom
Andarist:port/disallow-type-interface-inblockless-statements

Conversation

@Andarist

@Andarist Andarist commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings June 4, 2025 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Ports the TypeScript check to forbid type/interface declarations in statements without block bodies and updates error baselines accordingly

  • Adds grammar errors in the Go checker when a type or interface appears in a blockless context
  • Updates/removes test baselines to reflect the new TS1156 errors
  • Cleans up obsolete .errors.txt.diff files

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
internal/checker/checker.go Added containerAllowsBlockScopedVariable checks for type/interface
testdata/baselines/reference/submodule/compiler/typeInterfaceDeclarationsInBlockStatements1.errors.txt Expanded expected errors to include the new interface-blockless error
testdata/baselines/reference/submodule/compiler/typeAliasDeclarationEmit3.errors.txt Added expected errors for type-alias-blockless contexts
testdata/baselines/reference/submodule/compiler/*.errors.txt.diff Removed outdated diff artifacts
Comments suppressed due to low confidence (2)

testdata/baselines/reference/submodule/compiler/typeAliasDeclarationEmit3.errors.txt.diff:1

  • [nitpick] This .errors.txt.diff file is now empty; consider removing it entirely to avoid cluttering the testbaseline directory.
<no content>

internal/checker/checker.go:6426

  • The blockless declaration check in checkTypeAliasDeclaration isn’t guarded by the result of c.checkGrammarModifiers, unlike the interface version; consider applying the same guard to maintain consistent early-exit behavior.
if !c.containerAllowsBlockScopedVariable(node.Parent) {

if !c.checkGrammarModifiers(node) {
c.checkGrammarInterfaceDeclaration(node.AsInterfaceDeclaration())
}
if !c.containerAllowsBlockScopedVariable(node.Parent) {

Copilot AI Jun 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic for disallowing blockless type and interface declarations is duplicated; consider extracting a helper to reduce code duplication.

Copilot uses AI. Check for mistakes.
@jakebailey
jakebailey added this pull request to the merge queue Jun 4, 2025
Merged via the queue into microsoft:main with commit 9b963fd Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants