Skip to content

Fix missing TS2385 error for constructor overload visibility disagreement#2706

Merged
andrewbranch merged 3 commits intomainfrom
copilot/fix-overload-signature-error
Feb 7, 2026
Merged

Fix missing TS2385 error for constructor overload visibility disagreement#2706
andrewbranch merged 3 commits intomainfrom
copilot/fix-overload-signature-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 6, 2026

tsgo was not reporting TS2385 when constructor overload signatures had mismatched visibility modifiers (public/private/protected), while TypeScript correctly errors:

class Foo {
    private constructor(init: string)  // Should error
    constructor(init: number)
    constructor(init: number | string) { }
}

Changes

  • internal/checker/checker.go: Added core.OrElse fallback in checkFlagAgreementBetweenOverloads when reporting visibility disagreement errors. GetNameOfDeclaration returns nil for constructors (they have no name field), causing diagnostics to be created with no location and silently ignored. Now falls back to the overload node itself, matching TypeScript's getNameOfDeclaration(o) || o pattern.

  • Test coverage: The fix corrects the existing submodule test classConstructorOverloadsAccessibility.ts from the TypeScript test suite, which now properly reports 3 errors instead of 0.

Original prompt

This section details on the original issue you should resolve

<issue_title>Missing error for overload signature visibility disagreement</issue_title>
<issue_description>## Steps to reproduce

class Foo {
    private constructor(init: string)
    constructor(init: number)
    constructor(init: number | string) {
        
    }
}

Behavior with typescript@6.0

test.ts:2:5 - error TS2385: Overload signatures must all be public, private or protected.

2     private constructor(init: string)
      ~~~~~~~~~~~~~~~~~~~

Behavior with tsgo

No errors</issue_description>

<agent_instructions>Check _submodules/TypeScript to verify where the error is supposed to be issued</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ment

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing error for overload signature visibility disagreement Fix missing TS2385 error for constructor overload visibility disagreement Feb 6, 2026
Copilot AI requested a review from andrewbranch February 6, 2026 21:29
@andrewbranch
Copy link
Copy Markdown
Member

@copilot delete the new test and baselines because it looks like an existing submodule test was fixed.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot delete the new test and baselines because it looks like an existing submodule test was fixed.

Done. Deleted the new test case and baselines. The fix now only includes the code change and the corrected submodule baseline. (4f1f721)

@andrewbranch andrewbranch marked this pull request as ready for review February 6, 2026 23:24
Copilot AI review requested due to automatic review settings February 6, 2026 23:24
c.error(ast.GetNameOfDeclaration(overload), diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient)
case deviation&(ast.ModifierFlagsPrivate|ast.ModifierFlagsProtected) != 0:
c.error(ast.GetNameOfDeclaration(overload), diagnostics.Overload_signatures_must_all_be_public_private_or_protected)
c.error(core.OrElse(ast.GetNameOfDeclaration(overload), overload), diagnostics.Overload_signatures_must_all_be_public_private_or_protected)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Old code was

error(getNameOfDeclaration(o) || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);

sneaky

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a TypeScript conformance gap where tsgo failed to emit TS2385 for constructor overloads with mismatched visibility by ensuring diagnostics attach to a valid node for constructors.

Changes:

  • Fix diagnostic location for TS2385 visibility mismatch by falling back from missing constructor name nodes to the overload node.
  • Update the conformance baseline to reflect the now-reported TS2385 errors.
  • Remove the no-longer-needed baseline .diff artifact.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/checker/checker.go Ensures TS2385 is reported for constructor overload visibility mismatches by using a valid fallback node for errors.
testdata/baselines/reference/submodule/conformance/classConstructorOverloadsAccessibility.errors.txt Updates expected error output to include the newly surfaced TS2385 diagnostics and spans.
testdata/baselines/reference/submodule/conformance/classConstructorOverloadsAccessibility.errors.txt.diff Removes an outdated/now-unnecessary diff artifact after updating the baseline.
Comments suppressed due to low confidence (1)

internal/checker/checker.go:1

  • Only the TS2385 (visibility) branch uses a fallback node when GetNameOfDeclaration(overload) is nil (constructors). The other diagnostic branches still pass GetNameOfDeclaration(overload) directly, which can reintroduce the same ‘missing diagnostic location’ issue for constructors if those deviation cases ever apply. Consider computing a single errorNode := core.OrElse(ast.GetNameOfDeclaration(overload), overload) once and using it for all c.error(...) calls in this switch.

@andrewbranch andrewbranch added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit 084e5eb Feb 7, 2026
26 checks passed
@andrewbranch andrewbranch deleted the copilot/fix-overload-signature-error branch February 7, 2026 00:06
Copilot AI added a commit that referenced this pull request Feb 25, 2026
…ment (#2706)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
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.

Missing error for overload signature visibility disagreement

4 participants