Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
most pr feedback
  • Loading branch information
weswigham committed Dec 9, 2015
commit 028484664d019153ed23791ffa88014890986a54
29 changes: 13 additions & 16 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5103,7 +5103,7 @@ namespace ts {
const targetPredicate = target as PredicateType;
if (sourcePredicate.predicate.kind !== targetPredicate.predicate.kind) {
if (reportErrors) {
reportError(Diagnostics.A_this_based_type_guard_is_not_assignable_to_a_parameter_based_type_guard);
reportError(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard);
reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target));
}
return Ternary.False;
Expand Down Expand Up @@ -6506,10 +6506,7 @@ namespace ts {

function isAssignedInBinaryExpression(node: BinaryExpression) {
if (node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment) {
let n = node.left;
while (n.kind === SyntaxKind.ParenthesizedExpression) {
n = (<ParenthesizedExpression>n).expression;
}
const n = skipParenthesizedNodes(node.left);
if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>n) === symbol) {
return true;
}
Expand Down Expand Up @@ -6844,13 +6841,6 @@ namespace ts {
return type;
}

function skipParenthesizedNodes(expression: Expression): Expression {
while (expression.kind === SyntaxKind.ParenthesizedExpression) {
expression = (expression as ParenthesizedExpression).expression;
}
return expression;
}

function getSymbolAtTypePredicatePosition(expr: Expression): Symbol {
expr = skipParenthesizedNodes(expr);
switch (expr.kind) {
Expand Down Expand Up @@ -6897,6 +6887,13 @@ namespace ts {
}
}

function skipParenthesizedNodes(expression: Expression): Expression {
while (expression.kind === SyntaxKind.ParenthesizedExpression) {
expression = (expression as ParenthesizedExpression).expression;
}
return expression;
}

function checkIdentifier(node: Identifier): Type {
const symbol = getResolvedSymbol(node);

Expand Down Expand Up @@ -11085,7 +11082,7 @@ namespace ts {
return -1;
}

function isInLegalTypePredicatePosition(node: Node): boolean {
function isInLegalParameterTypePredicatePosition(node: Node): boolean {
switch (node.parent.kind) {
case SyntaxKind.ArrowFunction:
case SyntaxKind.CallSignature:
Expand All @@ -11100,7 +11097,7 @@ namespace ts {
}

function isInLegalThisTypePredicatePosition(node: Node): boolean {
if (isInLegalTypePredicatePosition(node)) {
if (isInLegalParameterTypePredicatePosition(node)) {
return true;
}
switch (node.parent.kind) {
Expand Down Expand Up @@ -14332,12 +14329,12 @@ namespace ts {
}

function checkTypePredicate(node: TypePredicateNode) {
if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalTypePredicatePosition(node)) {
if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalParameterTypePredicatePosition(node)) {
error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
}
else if (node.parameterName.kind === SyntaxKind.ThisType) {
if (!isInLegalThisTypePredicatePosition(node)) {
error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_in_class_or_interface_members_get_accessors_or_return_type_positions_for_functions_and_methods);
error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_within_a_class_or_interface_s_members_get_accessors_or_return_type_positions_for_functions_and_methods);
}
else {
getTypeFromThisTypeNode(node.parameterName as ThisTypeNode);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1647,11 +1647,11 @@
"category": "Error",
"code": 2517
},
"A 'this'-based type guard is not assignable to a parameter-based type guard": {
"A 'this'-based type guard is not compatible with a parameter-based type guard.": {
"category": "Error",
"code": 2518
},
"A 'this'-based type predicate is only allowed in class or interface members, get accessors, or return type positions for functions and methods": {
"A 'this'-based type predicate is only allowed within a class or interface's members, get accessors, or return type positions for functions and methods.": {
"category": "Error",
"code": 2519
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ namespace ts {
ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6
ThisType = 0x02000000, // This type
ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties
PredicateType = 0x08000000,
PredicateType = 0x08000000, // Predicate types are also Boolean types, but should not be considered Intrinsics - there's no way to capture this with flags

/* @internal */
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

More than anything else, can you leave a comment about the interaction here with intrinsicName?

Expand Down