@@ -4016,6 +4016,7 @@ module ts {
40164016 if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True;
40174017 }
40184018 }
4019+ let saveErrorInfo = errorInfo;
40194020 if (source.flags & TypeFlags.Union || target.flags & TypeFlags.Union) {
40204021 if (relation === identityRelation) {
40214022 if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union) {
@@ -4054,25 +4055,34 @@ module ts {
40544055 return result;
40554056 }
40564057 }
4057- else {
4058- let saveErrorInfo = errorInfo;
4059- if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
4060- // We have type references to same target type, see if relationship holds for all type arguments
4061- if (result = typesRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, reportErrors)) {
4062- return result;
4063- }
4058+ else if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
4059+ // We have type references to same target type, see if relationship holds for all type arguments
4060+ if (result = typesRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, reportErrors)) {
4061+ return result;
40644062 }
4065- // Even if relationship doesn't hold for type arguments, it may hold in a structural comparison
4066- // Report structural errors only if we haven't reported any errors yet
4067- let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
4068- // identity relation does not use apparent type
4069- let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
4070- if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType &&
4071- (result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors))) {
4063+ }
4064+
4065+ // Even if relationship doesn't hold for unions, type parameters, or generic type references,
4066+ // it may hold in a structural comparison.
4067+ // Report structural errors only if we haven't reported any errors yet
4068+ let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
4069+ // identity relation does not use apparent type
4070+ let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
4071+ if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType) {
4072+ if (result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors)) {
40724073 errorInfo = saveErrorInfo;
40734074 return result;
40744075 }
40754076 }
4077+ else if (source.flags & TypeFlags.TypeParameter && sourceOrApparentType.flags & TypeFlags.Union) {
4078+ // We clear the errors first because the following check often gives a better error than
4079+ // the union comparison above if it is applicable.
4080+ errorInfo = saveErrorInfo;
4081+ if (result = isRelatedTo(sourceOrApparentType, target, reportErrors)) {
4082+ return result;
4083+ }
4084+ }
4085+
40764086 if (reportErrors) {
40774087 headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1;
40784088 let sourceType = typeToString(source);
@@ -12943,6 +12953,11 @@ module ts {
1294312953 }
1294412954 }
1294512955
12956+ function isEvalOrArgumentsIdentifier(node: Node): boolean {
12957+ return node.kind === SyntaxKind.Identifier &&
12958+ ((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
12959+ }
12960+
1294612961 function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
1294712962 if (node.typeParameters) {
1294812963 return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
0 commit comments