Skip to content

Commit 98cf317

Browse files
authored
Add error message for set accessor vsibility issues (#33683)
1 parent f89de95 commit 98cf317

7 files changed

+63
-1
lines changed

src/compiler/diagnosticMessages.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,6 @@
30723072
"category": "Error",
30733073
"code": 4094
30743074
},
3075-
30763075
"Public static method '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named.": {
30773076
"category": "Error",
30783077
"code": 4095
@@ -3117,6 +3116,18 @@
31173116
"category": "Error",
31183117
"code": 4105
31193118
},
3119+
"Parameter '{0}' of accessor has or is using private name '{1}'.": {
3120+
"category": "Error",
3121+
"code": 4106
3122+
},
3123+
"Parameter '{0}' of accessor has or is using name '{1}' from private module '{2}'.": {
3124+
"category": "Error",
3125+
"code": 4107
3126+
},
3127+
"Parameter '{0}' of accessor has or is using name '{1}' from external module '{2}' but cannot be named.": {
3128+
"category": "Error",
3129+
"code": 4108
3130+
},
31203131

31213132
"The current host does not support the '{0}' option.": {
31223133
"category": "Error",

src/compiler/transformers/declarations/diagnostics.ts

+7
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ namespace ts {
373373
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
374374
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
375375
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
376+
case SyntaxKind.SetAccessor:
377+
case SyntaxKind.GetAccessor:
378+
return symbolAccessibilityResult.errorModuleName ?
379+
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
380+
Diagnostics.Parameter_0_of_accessor_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
381+
Diagnostics.Parameter_0_of_accessor_has_or_is_using_name_1_from_private_module_2 :
382+
Diagnostics.Parameter_0_of_accessor_has_or_is_using_private_name_1;
376383

377384
default:
378385
return Debug.fail(`Unknown parent for parameter: ${(ts as any).SyntaxKind[node.parent.kind]}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS2304: Cannot find name 'DoesNotExist'.
2+
tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
3+
4+
5+
==== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts (2 errors) ====
6+
export class Q {
7+
set bet(arg: DoesNotExist) {}
8+
~~~~~~~~~~~~
9+
!!! error TS2304: Cannot find name 'DoesNotExist'.
10+
~~~~~~~~~~~~
11+
!!! error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [accessorDeclarationEmitVisibilityErrors.ts]
2+
export class Q {
3+
set bet(arg: DoesNotExist) {}
4+
}
5+
6+
//// [accessorDeclarationEmitVisibilityErrors.js]
7+
export class Q {
8+
set bet(arg) { }
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts ===
2+
export class Q {
3+
>Q : Symbol(Q, Decl(accessorDeclarationEmitVisibilityErrors.ts, 0, 0))
4+
5+
set bet(arg: DoesNotExist) {}
6+
>bet : Symbol(Q.bet, Decl(accessorDeclarationEmitVisibilityErrors.ts, 0, 16))
7+
>arg : Symbol(arg, Decl(accessorDeclarationEmitVisibilityErrors.ts, 1, 12))
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/accessorDeclarationEmitVisibilityErrors.ts ===
2+
export class Q {
3+
>Q : Q
4+
5+
set bet(arg: DoesNotExist) {}
6+
>bet : any
7+
>arg : any
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @target: es6
2+
// @strict: true
3+
// @declaration: true
4+
5+
export class Q {
6+
set bet(arg: DoesNotExist) {}
7+
}

0 commit comments

Comments
 (0)