Skip to content

Commit

Permalink
Clearifies protected error message (#42599)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikeshaq authored Mar 9, 2021
1 parent 3d53661 commit 626e78c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26538,7 +26538,7 @@ namespace ts {
type = (type as TypeParameter).isThisType ? getConstraintOfTypeParameter(<TypeParameter>type)! : getBaseConstraintOfType(<TypeParameter>type)!; // TODO: GH#18217 Use a different variable that's allowed to be undefined
}
if (!type || !hasBaseType(type, enclosingClass)) {
error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1_This_is_an_instance_of_class_2, symbolToString(prop), typeToString(enclosingClass), typeToString(type));
return false;
}
return true;
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@
"category": "Error",
"code": 2445
},
"Property '{0}' is protected and only accessible through an instance of class '{1}'.": {
"Property '{0}' is protected and only accessible through an instance of class '{1}'. This is an instance of class '{2}'.": {
"category": "Error",
"code": 2446
},
Expand Down Expand Up @@ -6258,7 +6258,6 @@
"code": 95159
},


"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
"code": 18004
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(15,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(32,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(34,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(32,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Base'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(34,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(35,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(36,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(36,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. This is an instance of class 'Base'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. This is an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(55,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(77,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(93,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(94,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(95,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Base'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(77,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(93,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Base'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(94,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(95,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(96,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(110,3): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(111,4): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
Expand Down Expand Up @@ -57,17 +57,17 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce

b.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Base'.
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Derived2'.
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. This is an instance of class 'Derived4'.
}
}
}
Expand All @@ -85,10 +85,10 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce

b.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. This is an instance of class 'Base'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. This is an instance of class 'Derived1'.
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~
Expand All @@ -112,17 +112,17 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce

b.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Base'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived1'.
d2.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived2'.
d3.x; // OK, accessed within their declaring class
d4.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. This is an instance of class 'Derived4'.
}
}
}
Expand All @@ -140,13 +140,13 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce

b.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Base'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Derived1'.
d2.x; // Error, isn't accessed through an instance of the enclosing class
~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. This is an instance of class 'Derived2'.
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
Expand Down
Loading

0 comments on commit 626e78c

Please sign in to comment.