Skip to content

Add error message for set accessor visibility issues #33683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3047,7 +3047,6 @@
"category": "Error",
"code": 4094
},

"Public static method '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": {
"category": "Error",
"code": 4095
Expand Down Expand Up @@ -3092,6 +3091,18 @@
"category": "Error",
"code": 4105
},
"Parameter '{0}' of accessor has or is using private name '{1}'.": {
"category": "Error",
"code": 4106
},
"Parameter '{0}' of accessor has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 4107
},
"Parameter '{0}' of accessor has or is using name '{1}' from external module '{2}' but cannot be named.": {
"category": "Error",
"code": 4108
},

"The current host does not support the '{0}' option.": {
"category": "Error",
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/transformers/declarations/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ namespace ts {
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
case SyntaxKind.SetAccessor:
case SyntaxKind.GetAccessor:
return symbolAccessibilityResult.errorModuleName ?
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Parameter_0_of_accessor_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Parameter_0_of_accessor_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Parameter_0_of_accessor_has_or_is_using_private_name_1;

default:
return Debug.fail(`Unknown parent for parameter: ${(ts as any).SyntaxKind[node.parent.kind]}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS2304: Cannot find name 'DoesNotExist'.
tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.


==== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts (2 errors) ====
export class Q {
set bet(arg: DoesNotExist) {}
~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

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

names that don't exist create a "is using private name" errors? ok..

Copy link
Member Author

Choose a reason for hiding this comment

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

Eeeeyup.

!!! error TS2304: Cannot find name 'DoesNotExist'.
~~~~~~~~~~~~
!!! error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [accessorDeclarationEmitVisibilityErrors.ts]
export class Q {
set bet(arg: DoesNotExist) {}
}

//// [accessorDeclarationEmitVisibilityErrors.js]
export class Q {
set bet(arg) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts ===
export class Q {
>Q : Symbol(Q, Decl(accessorDeclarationEmitVisibilityErrors.ts, 0, 0))

set bet(arg: DoesNotExist) {}
>bet : Symbol(Q.bet, Decl(accessorDeclarationEmitVisibilityErrors.ts, 0, 16))
>arg : Symbol(arg, Decl(accessorDeclarationEmitVisibilityErrors.ts, 1, 12))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts ===
export class Q {
>Q : Q

set bet(arg: DoesNotExist) {}
>bet : any
>arg : any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @target: es6
// @strict: true
// @declaration: true

export class Q {
set bet(arg: DoesNotExist) {}
}