Skip to content
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

error on set accessor without get accessor #26338

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22563,6 +22563,9 @@ namespace ts {
checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type);
checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, Diagnostics.get_and_set_accessor_must_have_the_same_this_type);
}
else if (node.kind === SyntaxKind.SetAccessor) {
error(node.name, Diagnostics.A_set_accessor_must_have_a_corresponding_get_accessor);
}
}
const returnType = getTypeOfAccessors(getSymbolOfNode(node));
if (node.kind === SyntaxKind.GetAccessor) {
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
"category": "Error",
"code": 1049
},
"A 'set' accessor must have a corresponding 'get' accessor.": {
"category": "Error",
"code": 1050
},
"A 'set' accessor cannot have an optional parameter.": {
"category": "Error",
"code": 1051
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
tests/cases/compiler/MemberAccessorDeclaration15.ts(2,8): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/MemberAccessorDeclaration15.ts(2,8): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/MemberAccessorDeclaration15.ts(2,12): error TS2369: A parameter property is only allowed in a constructor implementation.


==== tests/cases/compiler/MemberAccessorDeclaration15.ts (2 errors) ====
==== tests/cases/compiler/MemberAccessorDeclaration15.ts (3 errors) ====
class C {
set Foo(public a: number) { }
~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~~~~~~~~~~~~~~~~
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
Expand Down
23 changes: 22 additions & 1 deletion tests/baselines/reference/accessibilityModifiers.errors.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(6,24): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(11,26): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(16,23): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(21,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(22,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(23,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(24,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(24,24): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(26,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(27,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(28,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(29,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(29,26): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(31,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(32,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(33,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(34,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(34,23): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(39,13): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,12): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(41,13): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(42,12): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(42,23): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.


==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (16 errors) ====
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (23 errors) ====
// No errors
class C {
private static privateProperty;
private static privateMethod() { }
private static get privateGetter() { return 0; }
private static set privateSetter(a: number) { }
~~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.

protected static protectedProperty;
protected static protectedMethod() { }
protected static get protectedGetter() { return 0; }
protected static set protectedSetter(a: number) { }
~~~~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.

public static publicProperty;
public static publicMethod() { }
public static get publicGetter() { return 0; }
public static set publicSetter(a: number) { }
~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}

// Errors, accessibility modifiers must precede static
Expand All @@ -49,6 +62,8 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier
static private set privateSetter(a: number) { }
~~~~~~~
!!! error TS1029: 'private' modifier must precede 'static' modifier.
~~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.

static protected protectedProperty;
~~~~~~~~~
Expand All @@ -62,6 +77,8 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier
static protected set protectedSetter(a: number) { }
~~~~~~~~~
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
~~~~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.

static public publicProperty;
~~~~~~
Expand All @@ -75,6 +92,8 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier
static public set publicSetter(a: number) { }
~~~~~~
!!! error TS1029: 'public' modifier must precede 'static' modifier.
~~~~~~~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}

// Errors, multiple accessibility modifier
Expand All @@ -91,5 +110,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier
public public set setter(a: number) { }
~~~~~~
!!! error TS1028: Accessibility modifier already seen.
~~~~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(2,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(2,11): error TS2369: A parameter property is only allowed in a constructor implementation.
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,16): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,18): error TS2369: A parameter property is only allowed in a constructor implementation.


==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (2 errors) ====
==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (4 errors) ====
class C {
set X(public v) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~~~~~~~
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
static set X(public v2) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~~~~~~~~
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
}
8 changes: 7 additions & 1 deletion tests/baselines/reference/accessorWithES3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(10,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(10,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(19,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.


==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts (4 errors) ====
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts (6 errors) ====
// error to use accessors in ES3 mode

class C {
Expand All @@ -18,6 +20,8 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclara
class D {
set x(v) {
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
}
}
Expand All @@ -31,5 +35,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclara
var y = {
set b(v) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
}
27 changes: 27 additions & 0 deletions tests/baselines/reference/accessorWithES5.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES5.ts(8,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES5.ts(17,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.


==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES5.ts (2 errors) ====
class C {
get x() {
return 1;
}
}

class D {
set x(v) {
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}
}

var x = {
get a() { return 1 }
}

var y = {
set b(v) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}
8 changes: 7 additions & 1 deletion tests/baselines/reference/accessorWithInitializer.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
tests/cases/compiler/accessorWithInitializer.ts(2,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorWithInitializer.ts(2,9): error TS1052: A 'set' accessor parameter cannot have an initializer.
tests/cases/compiler/accessorWithInitializer.ts(3,16): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorWithInitializer.ts(3,16): error TS1052: A 'set' accessor parameter cannot have an initializer.


==== tests/cases/compiler/accessorWithInitializer.ts (2 errors) ====
==== tests/cases/compiler/accessorWithInitializer.ts (4 errors) ====
class C {
set X(v = 0) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~
!!! error TS1052: A 'set' accessor parameter cannot have an initializer.
static set X(v2 = 0) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~
!!! error TS1052: A 'set' accessor parameter cannot have an initializer.
}
8 changes: 7 additions & 1 deletion tests/baselines/reference/accessorWithRestParam.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
tests/cases/compiler/accessorWithRestParam.ts(2,9): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorWithRestParam.ts(2,11): error TS1053: A 'set' accessor cannot have rest parameter.
tests/cases/compiler/accessorWithRestParam.ts(3,16): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorWithRestParam.ts(3,18): error TS1053: A 'set' accessor cannot have rest parameter.


==== tests/cases/compiler/accessorWithRestParam.ts (2 errors) ====
==== tests/cases/compiler/accessorWithRestParam.ts (4 errors) ====
class C {
set X(...v) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~~
!!! error TS1053: A 'set' accessor cannot have rest parameter.
static set X(...v2) { }
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~~
!!! error TS1053: A 'set' accessor cannot have rest parameter.
}
5 changes: 4 additions & 1 deletion tests/baselines/reference/accessorWithoutBody2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
tests/cases/compiler/accessorWithoutBody2.ts(1,15): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/compiler/accessorWithoutBody2.ts(1,20): error TS1005: '{' expected.


==== tests/cases/compiler/accessorWithoutBody2.ts (1 errors) ====
==== tests/cases/compiler/accessorWithoutBody2.ts (2 errors) ====
var v = { set foo(a) }
~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~
!!! error TS1005: '{' expected.
5 changes: 4 additions & 1 deletion tests/baselines/reference/asyncSetter_es5.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
tests/cases/conformance/async/es5/asyncSetter_es5.ts(2,3): error TS1042: 'async' modifier cannot be used here.
tests/cases/conformance/async/es5/asyncSetter_es5.ts(2,13): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.


==== tests/cases/conformance/async/es5/asyncSetter_es5.ts (1 errors) ====
==== tests/cases/conformance/async/es5/asyncSetter_es5.ts (2 errors) ====
class C {
async set foo(value) {
~~~~~
!!! error TS1042: 'async' modifier cannot be used here.
~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}
}
5 changes: 4 additions & 1 deletion tests/baselines/reference/asyncSetter_es6.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
tests/cases/conformance/async/es6/asyncSetter_es6.ts(2,3): error TS1042: 'async' modifier cannot be used here.
tests/cases/conformance/async/es6/asyncSetter_es6.ts(2,13): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.


==== tests/cases/conformance/async/es6/asyncSetter_es6.ts (1 errors) ====
==== tests/cases/conformance/async/es6/asyncSetter_es6.ts (2 errors) ====
class C {
async set foo(value) {
~~~~~
!!! error TS1042: 'async' modifier cannot be used here.
~~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
}
}
8 changes: 7 additions & 1 deletion tests/baselines/reference/classAbstractAccessor.errors.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(3,17): error TS1318: An abstract accessor cannot have an implementation.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(5,17): error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(5,17): error TS1318: An abstract accessor cannot have an implementation.


==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (2 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (4 errors) ====
abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
abstract set b(x: string);
~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
abstract set bb(x: string) {} // error
~~
!!! error TS1050: A 'set' accessor must have a corresponding 'get' accessor.
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
}

Loading