Addresses CR feedback

This commit is contained in:
Tingan Ho 2015-06-08 11:41:08 +08:00
parent b1a8a5fe66
commit 51a43dd9d5
7 changed files with 62 additions and 33 deletions

0
bin/tsc Normal file → Executable file
View File

View File

@ -8649,21 +8649,31 @@ module ts {
}
else if (typePredicateNode.parameterName) {
let hasReportedError = false;
outer: for (let param of node.parameters) {
for (var param of node.parameters) {
if (hasReportedError) {
break;
}
if (param.name.kind === SyntaxKind.ObjectBindingPattern ||
param.name.kind === SyntaxKind.ArrayBindingPattern) {
for (let element of (<BindingPattern>param.name).elements) {
if (element.name.kind === SyntaxKind.Identifier &&
(<Identifier>element.name).text === typePredicateNode.parameterName.text) {
error(typePredicateNode.parameterName,
Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern,
typePredicate.parameterName);
hasReportedError = true;
break outer;
(function checkBindingPattern(elements: NodeArray<BindingElement>) {
for (let element of elements) {
if (element.name.kind === SyntaxKind.Identifier &&
(<Identifier>element.name).text === typePredicate.parameterName) {
error(typePredicateNode.parameterName,
Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern,
typePredicate.parameterName);
hasReportedError = true;
break;
}
else if(element.name.kind === SyntaxKind.ArrayBindingPattern ||
element.name.kind === SyntaxKind.ObjectBindingPattern) {
checkBindingPattern((<BindingPattern>element.name).elements);
}
}
}
})((<BindingPattern>param.name).elements);
}
}
if (!hasReportedError) {
@ -8675,7 +8685,7 @@ module ts {
}
else {
error(typePredicateNode,
Diagnostics.Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods);
Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
}
}
else {
@ -11317,7 +11327,7 @@ module ts {
function checkTypePredicate(node: TypePredicateNode) {
if(!isInLegalTypePredicatePosition(node)) {
error(node, Diagnostics.Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods);
error(node, Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
}
}

View File

@ -183,7 +183,7 @@ module ts {
Cannot_find_parameter_0: { code: 1225, category: DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
Parameter_0_is_not_in_the_same_position_as_parameter_1: { code: 1227, category: DiagnosticCategory.Error, key: "Parameter '{0}' is not in the same position as parameter '{1}'." },
Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "Type predicates are only allowed in return type position for functions and methods." },
Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "Type predicate are only allowed in return type position for functions and methods." },
Type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "Type predicate cannot reference a rest parameter." },
Type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: DiagnosticCategory.Error, key: "Type predicate cannot reference element '{0}' in a binding pattern." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },

View File

@ -719,7 +719,7 @@
"category": "Error",
"code": 1227
},
"Type predicates are only allowed in return type position for functions and methods.": {
"Type predicate are only allowed in return type position for functions and methods.": {
"category": "Error",
"code": 1228
},

View File

@ -20,22 +20,23 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(81,1):
Type predicate 'p2 is A' is not assignable to 'p1 is A'.
Parameter 'p2' is not in the same position as parameter 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(87,1): error TS2322: Type '(p1: any, p2: any, p3: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(92,9): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,16): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(94,20): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(92,9): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,16): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(94,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(101,16): error TS2409: Return type of constructor signature must be assignable to the instance type of the class
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,20): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,20): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,16): error TS2408: Setters cannot return a value.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,18): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,22): error TS1228: Type predicates are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,18): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,22): error TS1228: Type predicate are only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,20): error TS1229: Type predicate cannot reference a rest parameter.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(125,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (29 errors) ====
==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (30 errors) ====
class A {
propA: number;
@ -167,13 +168,13 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34
// Type predicates in non-return type positions
var b1: b is A;
~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
function b2(a: b is A) {};
~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
function b3(): A | b is A {
~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
return true;
};
@ -181,19 +182,19 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34
class D {
constructor(p1: A): p1 is C {
~~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
return true;
~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class
}
get m1(p1: A): p1 is C {
~~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
return true;
}
set m2(p1: A): p1 is C {
~~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
return true;
~~~~
!!! error TS2408: Setters cannot return a value.
@ -203,13 +204,13 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34
interface I1 {
new (p1: A): p1 is C;
~~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
}
interface I2 {
[index: number]: p1 is C;
~~~~~~~
!!! error TS1228: Type predicates are only allowed in return type position for functions and methods.
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
}
// Reference to rest parameter
@ -228,6 +229,12 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34
function b6([a, b, p1], p2, p3): p1 is A {
~~
!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
return true;
}
function b7({a, b, c: {p1}}, p2, p3): p1 is A {
~~
!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
return true;
}

View File

@ -129,6 +129,10 @@ function b5({a, b, p1}, p2, p3): p1 is A {
function b6([a, b, p1], p2, p3): p1 is A {
return true;
}
function b7({a, b, c: {p1}}, p2, p3): p1 is A {
return true;
}
//// [typeGuardFunctionErrors.js]
@ -253,3 +257,7 @@ function b6(_a, p2, p3) {
var a = _a[0], b = _a[1], p1 = _a[2];
return true;
}
function b7(_a, p2, p3) {
var a = _a.a, b = _a.b, p1 = _a.c.p1;
return true;
}

View File

@ -128,4 +128,8 @@ function b5({a, b, p1}, p2, p3): p1 is A {
function b6([a, b, p1], p2, p3): p1 is A {
return true;
}
function b7({a, b, c: {p1}}, p2, p3): p1 is A {
return true;
}