From 760a2968e908245dc87f2bf98554a99111ca4e59 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 31 Oct 2014 10:18:15 -0700 Subject: [PATCH 1/3] Improved type relation caching to fix #1002 --- src/compiler/checker.ts | 469 +++++++++++++++++++++++----------------- src/compiler/core.ts | 11 + 2 files changed, 277 insertions(+), 203 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fbed37c7c30..b0ccb426eb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2163,7 +2163,7 @@ module ts { return false; } for (var i = 0; i < s.length; i++) { - if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, isTypeIdenticalTo)) { + if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, compareTypes)) { return false; } } @@ -3209,38 +3209,32 @@ module ts { // TYPE CHECKING - var subtypeRelation: Map = {}; - var assignableRelation: Map = {}; - var identityRelation: Map = {}; + var subtypeRelation: Map = {}; + var assignableRelation: Map = {}; + var identityRelation: Map = {}; function isTypeIdenticalTo(source: Type, target: Type): boolean { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); } + function compareTypes(source: Type, target: Type): number { + return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? -1 : 0; + } + function isTypeSubtypeOf(source: Type, target: Type): boolean { return checkTypeSubtypeOf(source, target, /*errorNode*/ undefined); } - function checkTypeSubtypeOf( - source: Type, - target: Type, - errorNode: Node, - headMessage?: DiagnosticMessage, - containingMessageChain?: DiagnosticMessageChain): boolean { - - return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); - } - function isTypeAssignableTo(source: Type, target: Type): boolean { return checkTypeAssignableTo(source, target, /*errorNode*/ undefined); } - function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage): boolean { - return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); + function checkTypeSubtypeOf(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { + return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } - function isTypeRelatedTo(source: Type, target: Type, relation: Map): boolean { - return checkTypeRelatedTo(source, target, relation, /*errorNode*/ undefined); + function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage): boolean { + return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); } function isSignatureAssignableTo(source: Signature, target: Signature): boolean { @@ -3249,71 +3243,10 @@ module ts { return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined); } - function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean { - return isPropertyIdenticalToRecursive(sourceProp, targetProp, /*reportErrors*/ false, (s, t, _reportErrors) => isTypeIdenticalTo(s, t)); - } - - function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean { - if (!type.baseTypes.length || type.baseTypes.length === 1) { - return true; - } - - var seen: Map<{ prop: Symbol; containingType: Type }> = {}; - forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; }); - var ok = true; - - for (var i = 0, len = type.baseTypes.length; i < len; ++i) { - var base = type.baseTypes[i]; - var properties = getPropertiesOfObjectType(base); - for (var j = 0, proplen = properties.length; j < proplen; ++j) { - var prop = properties[j]; - if (!hasProperty(seen, prop.name)) { - seen[prop.name] = { prop: prop, containingType: base }; - } - else { - var existing = seen[prop.name]; - var isInheritedProperty = existing.containingType !== type; - if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) { - ok = false; - - var typeName1 = typeToString(existing.containingType); - var typeName2 = typeToString(base); - - var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2); - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); - addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine())); - } - } - } - } - - return ok; - } - - function isPropertyIdenticalToRecursive(sourceProp: Symbol, targetProp: Symbol, reportErrors: boolean, relate: (source: Type, target: Type, reportErrors: boolean) => boolean): boolean { - // Two members are considered identical when - // - they are public properties with identical names, optionality, and types, - // - they are private or protected properties originating in the same declaration and having identical types - if (sourceProp === targetProp) { - return true; - } - var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected); - var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected); - if (sourcePropAccessibility !== targetPropAccessibility) { - return false; - } - if (sourcePropAccessibility) { - return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); - } - else { - return isOptionalProperty(sourceProp) === isOptionalProperty(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); - } - } - function checkTypeRelatedTo( source: Type, target: Type, - relation: Map, + relation: Map, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { @@ -3327,7 +3260,7 @@ module ts { Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); - var result = isRelatedToWithCustomErrors(source, target, errorNode !== undefined, headMessage); + var result = isRelatedTo(source, target, errorNode !== undefined, headMessage); if (overflow) { error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } @@ -3337,54 +3270,55 @@ module ts { } addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine())); } - return result; + return result !== 0; function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } - function isRelatedTo(source: Type, target: Type, reportErrors?: boolean): boolean { - return isRelatedToWithCustomErrors(source, target, reportErrors, /*headMessage*/ undefined); - } - - function isRelatedToWithCustomErrors(source: Type, target: Type, reportErrors: boolean, headMessage: DiagnosticMessage): boolean { + // Compare two types and return + // Ternary.True if they are related with no assumptions, + // Ternary.Maybe if they are related with assumptions of other relationships, or + // Ternary.False if they are not related. + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary { + var result: Ternary; if (relation === identityRelation) { // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases - if (source === target) return true; + if (source === target) return Ternary.True; } else { - if (source === target) return true; - if (target.flags & TypeFlags.Any) return true; - if (source === undefinedType) return true; - if (source === nullType && target !== undefinedType) return true; - if (source.flags & TypeFlags.Enum && target === numberType) return true; - if (source.flags & TypeFlags.StringLiteral && target === stringType) return true; + if (source === target) return Ternary.True; + if (target.flags & TypeFlags.Any) return Ternary.True; + if (source === undefinedType) return Ternary.True; + if (source === nullType && target !== undefinedType) return Ternary.True; + if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; + if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { - if (source.flags & TypeFlags.Any) return true; - if (source === numberType && target.flags & TypeFlags.Enum) return true; + if (source.flags & TypeFlags.Any) return Ternary.True; + if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } } if (source.flags & TypeFlags.Union) { - if (unionTypeRelatedToType(source, target, reportErrors)) { - return true; + if (result = unionTypeRelatedToType(source, target, reportErrors)) { + return result; } } else if (target.flags & TypeFlags.Union) { - if (typeRelatedToUnionType(source, target, reportErrors)) { - return true; + if (result = typeRelatedToUnionType(source, target, reportErrors)) { + return result; } } else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { - if (typeParameterRelatedTo(source, target, reportErrors)) { - return true; + if (result = typeParameterRelatedTo(source, target, reportErrors)) { + return result; } } else { var saveErrorInfo = errorInfo; if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (source).target === (target).target) { // We have type references to same target type, see if relationship holds for all type arguments - if (typesRelatedTo((source).typeArguments, (target).typeArguments, reportErrors)) { - return true; + if (result = typesRelatedTo((source).typeArguments, (target).typeArguments, reportErrors)) { + return result; } } // Even if relationship doesn't hold for type arguments, it may hold in a structural comparison @@ -3393,9 +3327,9 @@ module ts { // identity relation does not use apparent type var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && - objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors)) { + (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors))) { errorInfo = saveErrorInfo; - return true; + return result; } } if (reportErrors) { @@ -3403,61 +3337,67 @@ module ts { Debug.assert(headMessage); reportError(headMessage, typeToString(source), typeToString(target)); } - return false; + return Ternary.False; } - function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): boolean { + function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): Ternary { var targetTypes = target.types; for (var i = 0, len = targetTypes.length; i < len; i++) { - if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { - return true; + var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1); + if (related) { + return related; } } - return false; + return Ternary.False; } - function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): boolean { + function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): Ternary { + var result = Ternary.True; var sourceTypes = source.types; for (var i = 0, len = sourceTypes.length; i < len; i++) { - if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { - return false; + var related = isRelatedTo(sourceTypes[i], target, reportErrors); + if (!related) { + return Ternary.False; } + result &= related; } - return true; + return result; } - function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): boolean { + function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): Ternary { + var result = Ternary.True; for (var i = 0, len = sources.length; i < len; i++) { - if (!isRelatedTo(sources[i], targets[i], reportErrors)) return false; + var related = isRelatedTo(sources[i], targets[i], reportErrors); + if (!related) { + return Ternary.False; + } + result &= related; } - return true; + return result; } - function typeParameterRelatedTo(source: TypeParameter, target: TypeParameter, reportErrors: boolean): boolean { + function typeParameterRelatedTo(source: TypeParameter, target: TypeParameter, reportErrors: boolean): Ternary { if (relation === identityRelation) { if (source.symbol.name !== target.symbol.name) { - return false; + return Ternary.False; } - // covers case when both type parameters does not have constraint (both equal to noConstraintType) if (source.constraint === target.constraint) { - return true; + return Ternary.True; } - if (source.constraint === noConstraintType || target.constraint === noConstraintType) { - return false; + return Ternary.False; } - return isRelatedTo(source.constraint, target.constraint, reportErrors); } else { while (true) { var constraint = getConstraintOfTypeParameter(source); - if (constraint === target) return true; + if (constraint === target) return Ternary.True; if (!(constraint && constraint.flags & TypeFlags.TypeParameter)) break; source = constraint; } - return false; + return Ternary.False; } } @@ -3466,18 +3406,23 @@ module ts { // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are // equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion // and issue an error. Otherwise, actually compare the structure of the two types. - function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { - if (overflow) return false; - var result: boolean; + function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { + if (overflow) { + return Ternary.False; + } var id = source.id + "," + target.id; - if ((result = relation[id]) !== undefined) return result; + var related = relation[id]; + if (related !== undefined) { + return related; + } if (depth > 0) { for (var i = 0; i < depth; i++) { - if (source === sourceStack[i] && target === targetStack[i]) return true; + // If source and target are already being compared, consider them related with assumptions + if (source === sourceStack[i] && target === targetStack[i]) return Ternary.Maybe; } if (depth === 100) { overflow = true; - return false; + return 0; } } else { @@ -3491,15 +3436,28 @@ module ts { var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) expandingFlags |= 1; if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack)) expandingFlags |= 2; - result = expandingFlags === 3 || - propertiesRelatedTo(source, target, reportErrors) && - signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors) && - signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors) && - stringIndexTypesRelatedTo(source, target, reportErrors) && - numberIndexTypesRelatedTo(source, target, reportErrors); + if (expandingFlags === 3) { + var result = Ternary.True; + } + else { + var result = propertiesRelatedTo(source, target, reportErrors); + if (result) { + result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors); + if (result) { + result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors); + if (result) { + result &= stringIndexTypesRelatedTo(source, target, reportErrors); + if (result) { + result &= numberIndexTypesRelatedTo(source, target, reportErrors); + } + } + } + } + } expandingFlags = saveExpandingFlags; depth--; - if (depth === 0) { + // Only cache results that are free of assumptions + if (result !== Ternary.Maybe) { relation[id] = result; } return result; @@ -3525,10 +3483,11 @@ module ts { return false; } - function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return propertiesIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target); } + var result = Ternary.True; var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; @@ -3539,7 +3498,7 @@ module ts { if (reportErrors) { reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } - return false; + return Ternary.False; } } else if (!(targetProp.flags & SymbolFlags.Prototype)) { @@ -3557,7 +3516,7 @@ module ts { typeToString(sourceFlags & NodeFlags.Private ? target : source)); } } - return false; + return Ternary.False; } } else if (targetFlags & NodeFlags.Protected) { @@ -3569,7 +3528,7 @@ module ts { reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } - return false; + return Ternary.False; } } else if (sourceFlags & NodeFlags.Protected) { @@ -3577,14 +3536,16 @@ module ts { reportError(Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } - return false; + return Ternary.False; } - if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) { + var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); + if (!related) { if (reportErrors) { reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } - return false; + return Ternary.False; } + result &= related; if (isOptionalProperty(sourceProp) && !isOptionalProperty(targetProp)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... @@ -3597,37 +3558,46 @@ module ts { reportError(Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } - return false; + return Ternary.False; } } } } - return true; + return result; } - function propertiesIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function propertiesIdenticalTo(source: ObjectType, target: ObjectType): Ternary { var sourceProperties = getPropertiesOfObjectType(source); var targetProperties = getPropertiesOfObjectType(target); if (sourceProperties.length !== targetProperties.length) { - return false; + return Ternary.False; } + var result = Ternary.True; for (var i = 0, len = sourceProperties.length; i < len; ++i) { var sourceProp = sourceProperties[i]; var targetProp = getPropertyOfObjectType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; + if (!targetProp) { + return Ternary.False; } + var related = compareProperties(sourceProp, targetProp, isRelatedTo); + if (!related) { + return Ternary.False; + } + result &= related; } - return true; + return result; } - function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return signaturesIdenticalTo(source, target, kind, reportErrors); + return signaturesIdenticalTo(source, target, kind); + } + if (target === anyFunctionType || source === anyFunctionType) { + return Ternary.True; } - if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); + var result = Ternary.True; var saveErrorInfo = errorInfo; outer: for (var i = 0; i < targetSignatures.length; i++) { var t = targetSignatures[i]; @@ -3636,7 +3606,9 @@ module ts { for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) { - if (signatureRelatedTo(s, t, localErrors)) { + var related = signatureRelatedTo(s, t, localErrors); + if (related) { + result &= related; errorInfo = saveErrorInfo; continue outer; } @@ -3644,18 +3616,18 @@ module ts { localErrors = false; } } - return false; + return Ternary.False; } } - return true; + return result; } - function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): boolean { + function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { if (source === target) { - return true; + return Ternary.True; } if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { - return false; + return Ternary.False; } var sourceMax = source.parameters.length; var targetMax = target.parameters.length; @@ -3680,45 +3652,52 @@ module ts { // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N source = getErasedSignature(source); target = getErasedSignature(target); + var result = Ternary.True; for (var i = 0; i < checkCount; i++) { var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; - if (!isRelatedTo(s, t, reportErrors)) { - if (!isRelatedTo(t, s, false)) { + var related = isRelatedTo(s, t, reportErrors); + if (!related) { + related = isRelatedTo(t, s, false); + if (!related) { if (reportErrors) { reportError(Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); } - return false; + return Ternary.False; } errorInfo = saveErrorInfo; } + result &= related; } var t = getReturnTypeOfSignature(target); - if (t === voidType) return true; + if (t === voidType) return result; var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); + return result & isRelatedTo(s, t, reportErrors); } - function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind): Ternary { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); if (sourceSignatures.length !== targetSignatures.length) { - return false; + return Ternary.False; } + var result = Ternary.True; for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo)) { - return false; + var related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo); + if (!related) { + return Ternary.False; } + result &= related; } - return true; + return result; } - function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.String, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.String, source, target); } var targetType = getIndexTypeOfType(target, IndexKind.String); if (targetType) { @@ -3727,21 +3706,23 @@ module ts { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } - return false; + return Ternary.False; } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { + var related = isRelatedTo(sourceType, targetType, reportErrors); + if (!related) { if (reportErrors) { reportError(Diagnostics.Index_signatures_are_incompatible); } - return false; + return Ternary.False; } + return related; } - return true; + return Ternary.True; } - function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.Number, source, target); } var targetType = getIndexTypeOfType(target, IndexKind.Number); if (targetType) { @@ -3751,53 +3732,93 @@ module ts { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } - return false; + return Ternary.False; } if (sourceStringType && sourceNumberType) { // If we know for sure we're testing both string and numeric index types then only report errors from the second one - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + var related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); } else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + var related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); } - if (!compatible) { + if (!related) { if (reportErrors) { reportError(Diagnostics.Index_signatures_are_incompatible); } - return false; + return Ternary.False; } + return related; } - return true; + return Ternary.True; } - function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType): Ternary { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); - return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); + if (!sourceType && !targetType) { + return Ternary.True; + } + if (sourceType && targetType) { + return isRelatedTo(sourceType, targetType); + } + return Ternary.False; } } - function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean { + function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean { + return compareProperties(sourceProp, targetProp, compareTypes) !== 0; + } + + function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary { + // Two members are considered identical when + // - they are public properties with identical names, optionality, and types, + // - they are private or protected properties originating in the same declaration and having identical types + if (sourceProp === targetProp) { + return Ternary.True; + } + var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected); + var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected); + if (sourcePropAccessibility !== targetPropAccessibility) { + return Ternary.False; + } + if (sourcePropAccessibility) { + if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) { + return Ternary.False; + } + return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); + } + else { + if (isOptionalProperty(sourceProp) !== isOptionalProperty(targetProp)) { + return Ternary.False; + } + return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); + } + } + + function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary { if (source === target) { - return true; + return Ternary.True; } if (source.parameters.length !== target.parameters.length || source.minArgumentCount !== target.minArgumentCount || source.hasRestParameter !== target.hasRestParameter) { - return false; + return Ternary.False; } + var result = Ternary.True; if (source.typeParameters && target.typeParameters) { if (source.typeParameters.length !== target.typeParameters.length) { - return false; + return Ternary.False; } for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { - return false; + var related = compareTypes(source.typeParameters[i], target.typeParameters[i]); + if (!related) { + return Ternary.False; } + result &= related; } } else if (source.typeParameters || source.typeParameters) { - return false; + return Ternary.False; } // Spec 1.0 Section 3.8.3 & 3.8.4: // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N @@ -3806,11 +3827,16 @@ module ts { for (var i = 0, len = source.parameters.length; i < len; i++) { var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!compareTypes(s, t)) { - return false; + var related = compareTypes(s, t); + if (!related) { + return Ternary.False; } + result &= related; } - return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + if (compareReturnTypes) { + result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } + return result; } function isSupertypeOfEach(candidate: Type, types: Type[]): boolean { @@ -4859,7 +4885,7 @@ module ts { if (!result) { result = signature; } - else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, isTypeIdenticalTo)) { + else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, compareTypes)) { return undefined; } } @@ -5251,7 +5277,7 @@ module ts { return typeArgumentsAreAssignable; } - function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map, excludeArgument: boolean[], reportErrors: boolean) { + function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map, excludeArgument: boolean[], reportErrors: boolean) { if (node.arguments) { for (var i = 0; i < node.arguments.length; i++) { var arg = node.arguments[i]; @@ -5389,7 +5415,7 @@ module ts { return resolveErrorCall(node); - function chooseOverload(candidates: Signature[], relation: Map, excludeArgument: boolean[]) { + function chooseOverload(candidates: Signature[], relation: Map, excludeArgument: boolean[]) { for (var i = 0; i < candidates.length; i++) { if (!signatureHasCorrectArity(node, candidates[i])) { continue; @@ -7574,6 +7600,43 @@ module ts { return true; } + function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean { + if (!type.baseTypes.length || type.baseTypes.length === 1) { + return true; + } + + var seen: Map<{ prop: Symbol; containingType: Type }> = {}; + forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; }); + var ok = true; + + for (var i = 0, len = type.baseTypes.length; i < len; ++i) { + var base = type.baseTypes[i]; + var properties = getPropertiesOfObjectType(base); + for (var j = 0, proplen = properties.length; j < proplen; ++j) { + var prop = properties[j]; + if (!hasProperty(seen, prop.name)) { + seen[prop.name] = { prop: prop, containingType: base }; + } + else { + var existing = seen[prop.name]; + var isInheritedProperty = existing.containingType !== type; + if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) { + ok = false; + + var typeName1 = typeToString(existing.containingType); + var typeName2 = typeToString(base); + + var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2); + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); + addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine())); + } + } + } + } + + return ok; + } + function checkInterfaceDeclaration(node: InterfaceDeclaration) { checkTypeParameters(node.typeParameters); if (fullTypeCheck) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6e9f3a4110b..0b39063d5e3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,6 +1,17 @@ /// module ts { + + // Ternary values are defined such that + // x & y is False if either x or y is False. + // x & y is Maybe if either x or y is Maybe, but neither x or y is False. + // x & y is True if x and y are both True. + export enum Ternary { + False = 0, + Maybe = 1, + True = -1 + } + export interface Map { [index: string]: T; } From 4555090cc97cc58e99ee22dfb8c7d3e5dde3c2ad Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 31 Oct 2014 10:19:31 -0700 Subject: [PATCH 2/3] Accepting new baselines --- .../reference/arrayAssignmentTest1.errors.txt | 6 ---- .../baselines/reference/arrayCast.errors.txt | 2 -- ...gnmentCompatWithCallSignatures4.errors.txt | 8 ------ ...tCompatWithConstructSignatures4.errors.txt | 8 ------ ...ignmentCompatWithNumericIndexer.errors.txt | 4 --- ...gnmentCompatWithNumericIndexer2.errors.txt | 4 --- ...ignmentCompatWithObjectMembers4.errors.txt | 28 ------------------- ...signmentCompatWithStringIndexer.errors.txt | 8 ------ ...ignmentCompatWithStringIndexer2.errors.txt | 8 ------ .../reference/castingTuple.errors.txt | 2 -- ...AnnotationAndInvalidInitializer.errors.txt | 2 -- ...AssignmentCompatWithInterfaces1.errors.txt | 24 ---------------- .../genericTypeAssertions1.errors.txt | 4 +-- .../interfaceAssignmentCompat.errors.txt | 2 -- .../lastPropertyInLiteralWins.errors.txt | 4 --- .../objectLiteralIndexerErrors.errors.txt | 2 -- .../subtypingWithNumericIndexer2.errors.txt | 2 -- .../subtypingWithNumericIndexer3.errors.txt | 2 -- .../subtypingWithObjectMembers.errors.txt | 10 ------- .../subtypingWithObjectMembers2.errors.txt | 10 ------- .../subtypingWithObjectMembers3.errors.txt | 10 ------- .../subtypingWithStringIndexer2.errors.txt | 2 -- .../subtypingWithStringIndexer3.errors.txt | 2 -- 23 files changed, 1 insertion(+), 153 deletions(-) diff --git a/tests/baselines/reference/arrayAssignmentTest1.errors.txt b/tests/baselines/reference/arrayAssignmentTest1.errors.txt index 9d606ec6d90..48037451fb2 100644 --- a/tests/baselines/reference/arrayAssignmentTest1.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest1.errors.txt @@ -26,13 +26,10 @@ tests/cases/compiler/arrayAssignmentTest1.ts(70,1): error TS2323: Type 'C3[]' is Property 'C2M1' is missing in type 'C3'. tests/cases/compiler/arrayAssignmentTest1.ts(75,1): error TS2323: Type 'C2[]' is not assignable to type 'C3[]'. Type 'C2' is not assignable to type 'C3'. - Property 'CM3M1' is missing in type 'C2'. tests/cases/compiler/arrayAssignmentTest1.ts(76,1): error TS2323: Type 'C1[]' is not assignable to type 'C3[]'. Type 'C1' is not assignable to type 'C3'. - Property 'CM3M1' is missing in type 'C1'. tests/cases/compiler/arrayAssignmentTest1.ts(77,1): error TS2323: Type 'I1[]' is not assignable to type 'C3[]'. Type 'I1' is not assignable to type 'C3'. - Property 'CM3M1' is missing in type 'I1'. tests/cases/compiler/arrayAssignmentTest1.ts(79,1): error TS2323: Type '() => C1' is not assignable to type 'any[]'. Property 'push' is missing in type '() => C1'. tests/cases/compiler/arrayAssignmentTest1.ts(80,1): error TS2323: Type '{ one: number; }' is not assignable to type 'any[]'. @@ -162,17 +159,14 @@ tests/cases/compiler/arrayAssignmentTest1.ts(85,1): error TS2323: Type 'I1' is n ~~~~~~ !!! error TS2323: Type 'C2[]' is not assignable to type 'C3[]'. !!! error TS2323: Type 'C2' is not assignable to type 'C3'. -!!! error TS2323: Property 'CM3M1' is missing in type 'C2'. arr_c3 = arr_c1_2; // should be an error - is ~~~~~~ !!! error TS2323: Type 'C1[]' is not assignable to type 'C3[]'. !!! error TS2323: Type 'C1' is not assignable to type 'C3'. -!!! error TS2323: Property 'CM3M1' is missing in type 'C1'. arr_c3 = arr_i1_2; // should be an error - is ~~~~~~ !!! error TS2323: Type 'I1[]' is not assignable to type 'C3[]'. !!! error TS2323: Type 'I1' is not assignable to type 'C3'. -!!! error TS2323: Property 'CM3M1' is missing in type 'I1'. arr_any = f1; // should be an error - is ~~~~~~~ diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index 10562cc57e4..53be1c903a3 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,6 +1,5 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. Type '{ foo: string; }' is not assignable to type '{ id: number; }'. - Property 'id' is missing in type '{ foo: string; }'. ==== tests/cases/compiler/arrayCast.ts (1 errors) ==== @@ -10,7 +9,6 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. !!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'. -!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index 65b0a55a386..39735ec3844 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(53,9): error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ==== @@ -80,10 +76,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2323: Types of parameters 'y' and 'y' are incompatible. !!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2323: Types of property 'foo' are incompatible. -!!! error TS2323: Type 'string' is not assignable to type 'number'. var b10: (...x: T[]) => T; diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index a701b2834d1..60c1e7860be 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(53,9): error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(77,9): error TS2323: Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }'. Types of parameters 'x' and 'x' are incompatible. Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'. @@ -92,10 +88,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2323: Types of parameters 'y' and 'y' are incompatible. !!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2323: Types of property 'foo' are incompatible. -!!! error TS2323: Type 'string' is not assignable to type 'number'. var b10: new (...x: T[]) => T; diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt index 04816fdfc9c..5e82ac41f11 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt @@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(33,9): error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(37,9): error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts (6 errors) ==== @@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. var b2: { [x: number]: Derived2; } a = b2; // error @@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. var b3: { [x: number]: T; } a = b3; // ok diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt index 0c6bba73489..2cbc15b4b70 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt @@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(33,9): error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(37,9): error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts (6 errors) ==== @@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. var b2: { [x: number]: Derived2; } a = b2; // error @@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. var b3: { [x: number]: T; } a = b3; // ok diff --git a/tests/baselines/reference/assignmentCompatWithObjectMembers4.errors.txt b/tests/baselines/reference/assignmentCompatWithObjectMembers4.errors.txt index 90d2c9fb6f9..719aa2b3022 100644 --- a/tests/baselines/reference/assignmentCompatWithObjectMembers4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithObjectMembers4.errors.txt @@ -9,47 +9,36 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(29,5): error TS2323: Type 'T2' is not assignable to type 'S2'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(30,5): error TS2323: Type 'S2' is not assignable to type 'T2'. Types of property 'foo' are incompatible. Type 'Derived' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(31,5): error TS2323: Type 'T' is not assignable to type 'S2'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(32,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type 'S2'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(35,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(36,5): error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'. Types of property 'foo' are incompatible. Type 'Derived' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(41,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(42,5): error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'. Types of property 'foo' are incompatible. Type 'Derived' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(43,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(44,5): error TS2323: Type 'T2' is not assignable to type '{ foo: Derived; }'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(45,5): error TS2323: Type 'T' is not assignable to type '{ foo: Derived; }'. Types of property 'foo' are incompatible. Type 'Derived2' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(70,5): error TS2323: Type 'S' is not assignable to type 'T'. Types of property 'foo' are incompatible. Type 'Base' is not assignable to type 'Derived2'. @@ -57,15 +46,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(75,5): error TS2323: Type 'S2' is not assignable to type 'T2'. Types of property 'foo' are incompatible. Type 'Base' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(81,5): error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'. Types of property 'foo' are incompatible. Type 'Base' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(87,5): error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'. Types of property 'foo' are incompatible. Type 'Base' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts (17 errors) ==== @@ -112,25 +98,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'T2' is not assignable to type 'S2'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. t2 = s2; // error ~~ !!! error TS2323: Type 'S2' is not assignable to type 'T2'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Derived'. s2 = t; // error ~~ !!! error TS2323: Type 'T' is not assignable to type 'S2'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. s2 = b; // error ~~ !!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type 'S2'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. s2 = a2; // ok a = b; // error @@ -138,13 +120,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. b = a; // error ~ !!! error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Derived'. a = s; // ok a = s2; // ok a = a2; // ok @@ -154,31 +134,26 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. b2 = a2; // error ~~ !!! error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Derived'. a2 = b; // error ~~ !!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. a2 = t2; // error ~~ !!! error TS2323: Type 'T2' is not assignable to type '{ foo: Derived; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. a2 = t; // error ~~ !!! error TS2323: Type 'T' is not assignable to type '{ foo: Derived; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Derived2'. } module WithBase { @@ -218,7 +193,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'S2' is not assignable to type 'T2'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. s2 = t; // ok s2 = b; // ok s2 = a2; // ok @@ -229,7 +203,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. a = s; // ok a = s2; // ok a = a2; // ok @@ -240,7 +213,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'. !!! error TS2323: Types of property 'foo' are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. a2 = b; // ok a2 = t2; // ok a2 = t; // ok diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt index 3d6a3c48d68..a560ddc5b68 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt @@ -9,25 +9,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(33,5): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(41,5): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(46,9): error TS2323: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(47,9): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(50,9): error TS2323: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(51,9): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts (8 errors) ==== @@ -78,7 +74,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. class B2 extends A { [x: string]: Derived2; // ok @@ -91,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. function foo() { var b3: { [x: string]: Derived; }; @@ -106,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. var b4: { [x: string]: Derived2; }; a3 = b4; // error @@ -119,6 +112,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt index d84196f9dcc..672e51b74ae 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt @@ -9,25 +9,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(33,5): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(41,5): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(46,9): error TS2323: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(47,9): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(50,9): error TS2323: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(51,9): error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. - Property 'baz' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts (8 errors) ==== @@ -78,7 +74,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. interface B2 extends A { [x: string]: Derived2; // ok @@ -91,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'Base' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. function foo() { var b3: { [x: string]: Derived; }; @@ -106,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived'. -!!! error TS2323: Property 'bar' is missing in type 'Base'. var b4: { [x: string]: Derived2; }; a3 = b4; // error @@ -119,6 +112,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2323: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'T' is not assignable to type 'Derived2'. -!!! error TS2323: Property 'baz' is missing in type 'Base'. } } \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 9bf9c4f24fb..f4efed6f1d1 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -8,7 +8,6 @@ tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2352: Neithe tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other. Types of property '0' are incompatible. Type 'C' is not assignable to type 'A'. - Property 'a' is missing in type 'C'. tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other. Types of property 'pop' are incompatible. @@ -58,7 +57,6 @@ tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot !!! error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other. !!! error TS2352: Types of property '0' are incompatible. !!! error TS2352: Type 'C' is not assignable to type 'A'. -!!! error TS2352: Property 'a' is missing in type 'C'. var array1 = numStrTuple; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. diff --git a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt index 4222edc2dbd..023569e0762 100644 --- a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt +++ b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt @@ -29,7 +29,6 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd Type 'A' is not assignable to type 'A'. Property 'name' is missing in type 'A'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2323: Type 'A' is not assignable to type 'A'. - Property 'name' is missing in type 'A'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(52,5): error TS2323: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'. Type 'boolean' is not assignable to type 'string'. @@ -131,7 +130,6 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd var aClassInModule: M.A = new N.A(); ~~~~~~~~~~~~~~ !!! error TS2323: Type 'A' is not assignable to type 'A'. -!!! error TS2323: Property 'name' is missing in type 'A'. var aFunctionInModule: typeof M.F2 = F2; ~~~~~~~~~~~~~~~~~ !!! error TS2323: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'. diff --git a/tests/baselines/reference/genericAssignmentCompatWithInterfaces1.errors.txt b/tests/baselines/reference/genericAssignmentCompatWithInterfaces1.errors.txt index 0ca20061fef..965523476a7 100644 --- a/tests/baselines/reference/genericAssignmentCompatWithInterfaces1.errors.txt +++ b/tests/baselines/reference/genericAssignmentCompatWithInterfaces1.errors.txt @@ -8,24 +8,12 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(12,5): error TS23 tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(13,5): error TS2323: Type '{ x: A; }' is not assignable to type 'I'. Types of property 'x' are incompatible. Type 'A' is not assignable to type 'Comparable'. - Types of property 'compareTo' are incompatible. - Type '(other: number) => number' is not assignable to type '(other: string) => number'. - Types of parameters 'other' and 'other' are incompatible. - Type 'number' is not assignable to type 'string'. tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(16,5): error TS2323: Type '{ x: A; }' is not assignable to type 'I'. Types of property 'x' are incompatible. Type 'A' is not assignable to type 'Comparable'. - Types of property 'compareTo' are incompatible. - Type '(other: number) => number' is not assignable to type '(other: string) => number'. - Types of parameters 'other' and 'other' are incompatible. - Type 'number' is not assignable to type 'string'. tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS2323: Type 'K' is not assignable to type 'I'. Types of property 'x' are incompatible. Type 'A' is not assignable to type 'Comparable'. - Types of property 'compareTo' are incompatible. - Type '(other: number) => number' is not assignable to type '(other: string) => number'. - Types of parameters 'other' and 'other' are incompatible. - Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts (4 errors) ==== @@ -54,10 +42,6 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS23 !!! error TS2323: Type '{ x: A; }' is not assignable to type 'I'. !!! error TS2323: Types of property 'x' are incompatible. !!! error TS2323: Type 'A' is not assignable to type 'Comparable'. -!!! error TS2323: Types of property 'compareTo' are incompatible. -!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'. -!!! error TS2323: Types of parameters 'other' and 'other' are incompatible. -!!! error TS2323: Type 'number' is not assignable to type 'string'. var z = { x: new A() }; return z; } (); var a3: I = z; @@ -65,18 +49,10 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS23 !!! error TS2323: Type '{ x: A; }' is not assignable to type 'I'. !!! error TS2323: Types of property 'x' are incompatible. !!! error TS2323: Type 'A' is not assignable to type 'Comparable'. -!!! error TS2323: Types of property 'compareTo' are incompatible. -!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'. -!!! error TS2323: Types of parameters 'other' and 'other' are incompatible. -!!! error TS2323: Type 'number' is not assignable to type 'string'. var a4: I = >z; ~~ !!! error TS2323: Type 'K' is not assignable to type 'I'. !!! error TS2323: Types of property 'x' are incompatible. !!! error TS2323: Type 'A' is not assignable to type 'Comparable'. -!!! error TS2323: Types of property 'compareTo' are incompatible. -!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'. -!!! error TS2323: Types of parameters 'other' and 'other' are incompatible. -!!! error TS2323: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions1.errors.txt b/tests/baselines/reference/genericTypeAssertions1.errors.txt index 26a0d7d11aa..4178b6730cd 100644 --- a/tests/baselines/reference/genericTypeAssertions1.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions1.errors.txt @@ -4,7 +4,6 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,5): error TS2323: Type 'A' is not assignable to type 'number'. tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type 'A' nor type 'A>' is assignable to the other. Type 'number' is not assignable to type 'A'. - Property 'foo' is missing in type 'Number'. ==== tests/cases/compiler/genericTypeAssertions1.ts (3 errors) ==== @@ -20,5 +19,4 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type !!! error TS2323: Type 'A' is not assignable to type 'number'. ~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type 'A' nor type 'A>' is assignable to the other. -!!! error TS2352: Type 'number' is not assignable to type 'A'. -!!! error TS2352: Property 'foo' is missing in type 'Number'. \ No newline at end of file +!!! error TS2352: Type 'number' is not assignable to type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceAssignmentCompat.errors.txt b/tests/baselines/reference/interfaceAssignmentCompat.errors.txt index 04ae7ea89e4..d9791d5e6b8 100644 --- a/tests/baselines/reference/interfaceAssignmentCompat.errors.txt +++ b/tests/baselines/reference/interfaceAssignmentCompat.errors.txt @@ -1,7 +1,6 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(32,18): error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'. tests/cases/compiler/interfaceAssignmentCompat.ts(37,29): error TS2339: Property '_map' does not exist on type 'typeof Color'. tests/cases/compiler/interfaceAssignmentCompat.ts(42,13): error TS2323: Type 'IEye' is not assignable to type 'IFrenchEye'. - Property 'coleur' is missing in type 'IEye'. tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2323: Type 'IEye[]' is not assignable to type 'IFrenchEye[]'. Type 'IEye' is not assignable to type 'IFrenchEye'. @@ -55,7 +54,6 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2323: Type 'IEy eeks[j]=z[j]; // nope: element assignment ~~~~~~~ !!! error TS2323: Type 'IEye' is not assignable to type 'IFrenchEye'. -!!! error TS2323: Property 'coleur' is missing in type 'IEye'. } eeks=z; // nope: array assignment ~~~~ diff --git a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt index 0e5e9e540be..4bf5521d24d 100644 --- a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt +++ b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt @@ -3,8 +3,6 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate tests/cases/compiler/lastPropertyInLiteralWins.ts(12,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'. Types of property 'thunk' are incompatible. Type '(num: number) => void' is not assignable to type '(str: string) => void'. - Types of parameters 'num' and 'str' are incompatible. - Type 'number' is not assignable to type 'string'. tests/cases/compiler/lastPropertyInLiteralWins.ts(13,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'. @@ -40,6 +38,4 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate !!! error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'. !!! error TS2345: Types of property 'thunk' are incompatible. !!! error TS2345: Type '(num: number) => void' is not assignable to type '(str: string) => void'. -!!! error TS2345: Types of parameters 'num' and 'str' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt index 7cd580a219b..534a5a46208 100644 --- a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt @@ -1,7 +1,6 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2323: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [x: string]: A; [x: number]: B; }'. Index signatures are incompatible. Type 'A' is not assignable to type 'B'. - Property 'y' is missing in type 'A'. ==== tests/cases/compiler/objectLiteralIndexerErrors.ts (1 errors) ==== @@ -22,5 +21,4 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2323: Type '{ !!! error TS2323: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [x: string]: A; [x: number]: B; }'. !!! error TS2323: Index signatures are incompatible. !!! error TS2323: Type 'A' is not assignable to type 'B'. -!!! error TS2323: Property 'y' is missing in type 'A'. o1 = { x: c, 0: a }; // string indexer is any, number indexer is A \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt index 1c428ae99af..01b581b7306 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(24,25): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(32,15): error TS2430: Interface 'B3' incorrectly extends interface 'A'. Index signatures are incompatible. Type 'Base' is not assignable to type 'T'. @@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B extends A { ~~~~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. -!!! error TS2344: Property 'bar' is missing in type 'Base'. [x: number]: Derived; // error } diff --git a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt index e386fc69a3f..4da8bc0290a 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(24,21): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. Index signatures are incompatible. Type 'Base' is not assignable to type 'T'. @@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~~~~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. -!!! error TS2344: Property 'bar' is missing in type 'Base'. [x: number]: Derived; // error } diff --git a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt index e54ece580ca..e292c0867a7 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt @@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(22,7): error TS2415: Class 'B2' incorrectly extends base class 'A2'. Types of property '2.0' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(32,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Types of property ''2.0'' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(43,11): error TS2415: Class 'B' incorrectly extends base class 'A'. Types of property 'bar' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(53,11): error TS2415: Class 'B2' incorrectly extends base class 'A2'. Types of property '2.0' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(63,11): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Types of property ''2.0'' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (6 errors) ==== @@ -56,7 +51,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2415: Class 'B2' incorrectly extends base class 'A2'. !!! error TS2415: Types of property '2.0' are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. -!!! error TS2415: Property 'foo' is missing in type 'String'. 1: Derived; // ok 2: string; // error } @@ -71,7 +65,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2415: Class 'B3' incorrectly extends base class 'A3'. !!! error TS2415: Types of property ''2.0'' are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. -!!! error TS2415: Property 'foo' is missing in type 'String'. '1': Derived; // ok '2.0': string; // error } @@ -87,7 +80,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2415: Class 'B' incorrectly extends base class 'A'. !!! error TS2415: Types of property 'bar' are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. -!!! error TS2415: Property 'foo' is missing in type 'String'. foo: Derived2; // ok bar: string; // error } @@ -102,7 +94,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2415: Class 'B2' incorrectly extends base class 'A2'. !!! error TS2415: Types of property '2.0' are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. -!!! error TS2415: Property 'foo' is missing in type 'String'. 1: Derived2; // ok 2: string; // error } @@ -117,7 +108,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2415: Class 'B3' incorrectly extends base class 'A3'. !!! error TS2415: Types of property ''2.0'' are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. -!!! error TS2415: Property 'foo' is missing in type 'String'. '1': Derived2; // ok '2.0': string; // error } diff --git a/tests/baselines/reference/subtypingWithObjectMembers2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers2.errors.txt index 0ba28f2fcd0..3d46a6e5dc2 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers2.errors.txt @@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(27,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'. Types of property '2.0' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(37,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'. Types of property ''2.0'' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(50,15): error TS2430: Interface 'B' incorrectly extends interface 'A'. Types of property 'bar' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(60,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'. Types of property '2.0' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(70,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'. Types of property ''2.0'' are incompatible. Type 'string' is not assignable to type 'Base'. - Property 'foo' is missing in type 'String'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts (6 errors) ==== @@ -61,7 +56,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'. !!! error TS2430: Types of property '2.0' are incompatible. !!! error TS2430: Type 'string' is not assignable to type 'Base'. -!!! error TS2430: Property 'foo' is missing in type 'String'. 1: Derived; // ok 2: string; // error } @@ -76,7 +70,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'. !!! error TS2430: Types of property ''2.0'' are incompatible. !!! error TS2430: Type 'string' is not assignable to type 'Base'. -!!! error TS2430: Property 'foo' is missing in type 'String'. '1': Derived; // ok '2.0': string; // error } @@ -94,7 +87,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B' incorrectly extends interface 'A'. !!! error TS2430: Types of property 'bar' are incompatible. !!! error TS2430: Type 'string' is not assignable to type 'Base'. -!!! error TS2430: Property 'foo' is missing in type 'String'. foo?: Derived; // ok bar?: string; // error } @@ -109,7 +101,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'. !!! error TS2430: Types of property '2.0' are incompatible. !!! error TS2430: Type 'string' is not assignable to type 'Base'. -!!! error TS2430: Property 'foo' is missing in type 'String'. 1?: Derived; // ok 2?: string; // error } @@ -124,7 +115,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'. !!! error TS2430: Types of property ''2.0'' are incompatible. !!! error TS2430: Type 'string' is not assignable to type 'Base'. -!!! error TS2430: Property 'foo' is missing in type 'String'. '1'?: Derived; // ok '2.0'?: string; // error } diff --git a/tests/baselines/reference/subtypingWithObjectMembers3.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers3.errors.txt index 8db24b325c0..eaea4db7d62 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers3.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers3.errors.txt @@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(27,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'. Types of property '2.0' are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(37,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'. Types of property ''2.0'' are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(49,15): error TS2430: Interface 'B' incorrectly extends interface 'A'. Types of property 'bar' are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(59,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'. Types of property '2.0' are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(69,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'. Types of property ''2.0'' are incompatible. Type 'Base' is not assignable to type 'Derived'. - Property 'bar' is missing in type 'Base'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts (6 errors) ==== @@ -61,7 +56,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'. !!! error TS2430: Types of property '2.0' are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2430: Property 'bar' is missing in type 'Base'. 1: Derived; // ok 2: Base; // error } @@ -76,7 +70,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'. !!! error TS2430: Types of property ''2.0'' are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2430: Property 'bar' is missing in type 'Base'. '1': Derived; // ok '2.0': Base; // error } @@ -93,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B' incorrectly extends interface 'A'. !!! error TS2430: Types of property 'bar' are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2430: Property 'bar' is missing in type 'Base'. foo?: Derived; // ok bar?: Base; // error } @@ -108,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'. !!! error TS2430: Types of property '2.0' are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2430: Property 'bar' is missing in type 'Base'. 1?: Derived; // ok 2?: Base; // error } @@ -123,7 +114,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW !!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'. !!! error TS2430: Types of property ''2.0'' are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. -!!! error TS2430: Property 'bar' is missing in type 'Base'. '1'?: Derived; // ok '2.0'?: Base; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt index add4abd8975..cfe8f2b8e1d 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(24,25): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(32,15): error TS2430: Interface 'B3' incorrectly extends interface 'A'. Index signatures are incompatible. Type 'Base' is not assignable to type 'T'. @@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B extends A { ~~~~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. -!!! error TS2344: Property 'bar' is missing in type 'Base'. [x: string]: Derived; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt index 10c519cf304..91c9f7fd47e 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(24,21): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. - Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. Index signatures are incompatible. Type 'Base' is not assignable to type 'T'. @@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~~~~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. -!!! error TS2344: Property 'bar' is missing in type 'Base'. [x: string]: Derived; // error } From bf3a62909b962b3b3eb3ffbe8468f075864ad45f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 31 Oct 2014 14:23:29 -0700 Subject: [PATCH 3/3] Addressing feedback and adding regression tests --- src/compiler/checker.ts | 17 +++---- src/compiler/core.ts | 5 +- .../checkInfiniteExpansionTermination.js | 25 ++++++++++ .../checkInfiniteExpansionTermination.types | 44 ++++++++++++++++++ .../checkInfiniteExpansionTermination2.js | 27 +++++++++++ .../checkInfiniteExpansionTermination2.types | 46 +++++++++++++++++++ .../typeComparisonCaching.errors.txt | 45 ++++++++++++++++++ .../reference/typeComparisonCaching.js | 38 +++++++++++++++ .../checkInfiniteExpansionTermination.ts | 16 +++++++ .../checkInfiniteExpansionTermination2.ts | 16 +++++++ tests/cases/compiler/typeComparisonCaching.ts | 27 +++++++++++ 11 files changed, 297 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/checkInfiniteExpansionTermination.js create mode 100644 tests/baselines/reference/checkInfiniteExpansionTermination.types create mode 100644 tests/baselines/reference/checkInfiniteExpansionTermination2.js create mode 100644 tests/baselines/reference/checkInfiniteExpansionTermination2.types create mode 100644 tests/baselines/reference/typeComparisonCaching.errors.txt create mode 100644 tests/baselines/reference/typeComparisonCaching.js create mode 100644 tests/cases/compiler/checkInfiniteExpansionTermination.ts create mode 100644 tests/cases/compiler/checkInfiniteExpansionTermination2.ts create mode 100644 tests/cases/compiler/typeComparisonCaching.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0ccb426eb2..83cc54e1acc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3217,8 +3217,8 @@ module ts { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); } - function compareTypes(source: Type, target: Type): number { - return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? -1 : 0; + function compareTypes(source: Type, target: Type): Ternary { + return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False; } function isTypeSubtypeOf(source: Type, target: Type): boolean { @@ -3270,7 +3270,7 @@ module ts { } addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine())); } - return result !== 0; + return result !== Ternary.False; function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); @@ -3418,11 +3418,13 @@ module ts { if (depth > 0) { for (var i = 0; i < depth; i++) { // If source and target are already being compared, consider them related with assumptions - if (source === sourceStack[i] && target === targetStack[i]) return Ternary.Maybe; + if (source === sourceStack[i] && target === targetStack[i]) { + return Ternary.Maybe; + } } if (depth === 100) { overflow = true; - return 0; + return Ternary.False; } } else { @@ -3766,7 +3768,7 @@ module ts { } function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean { - return compareProperties(sourceProp, targetProp, compareTypes) !== 0; + return compareProperties(sourceProp, targetProp, compareTypes) !== Ternary.False; } function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary { @@ -3785,14 +3787,13 @@ module ts { if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) { return Ternary.False; } - return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } else { if (isOptionalProperty(sourceProp) !== isOptionalProperty(targetProp)) { return Ternary.False; } - return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } + return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0b39063d5e3..b233d3575b3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -5,7 +5,10 @@ module ts { // Ternary values are defined such that // x & y is False if either x or y is False. // x & y is Maybe if either x or y is Maybe, but neither x or y is False. - // x & y is True if x and y are both True. + // x & y is True if both x and y are True. + // x | y is False if both x and y are False. + // x | y is Maybe if either x or y is Maybe, but neither x or y is True. + // x | y is True if either x or y is True. export enum Ternary { False = 0, Maybe = 1, diff --git a/tests/baselines/reference/checkInfiniteExpansionTermination.js b/tests/baselines/reference/checkInfiniteExpansionTermination.js new file mode 100644 index 00000000000..ed52ea6b419 --- /dev/null +++ b/tests/baselines/reference/checkInfiniteExpansionTermination.js @@ -0,0 +1,25 @@ +//// [checkInfiniteExpansionTermination.ts] +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; // Needed, must be T[] +} + +// Needed +interface ISubject extends IObservable { } + +interface Foo { x } +interface Bar { y } + +var values: IObservable; +var values2: ISubject; +values = values2; + + +//// [checkInfiniteExpansionTermination.js] +// Regression test for #1002 +// Before fix this code would cause infinite loop +var values; +var values2; +values = values2; diff --git a/tests/baselines/reference/checkInfiniteExpansionTermination.types b/tests/baselines/reference/checkInfiniteExpansionTermination.types new file mode 100644 index 00000000000..bd4858126dd --- /dev/null +++ b/tests/baselines/reference/checkInfiniteExpansionTermination.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/checkInfiniteExpansionTermination.ts === +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { +>IObservable : IObservable +>T : T + + n: IObservable; // Needed, must be T[] +>n : IObservable +>IObservable : IObservable +>T : T +} + +// Needed +interface ISubject extends IObservable { } +>ISubject : ISubject +>T : T +>IObservable : IObservable +>T : T + +interface Foo { x } +>Foo : Foo +>x : any + +interface Bar { y } +>Bar : Bar +>y : any + +var values: IObservable; +>values : IObservable +>IObservable : IObservable +>Foo : Foo + +var values2: ISubject; +>values2 : ISubject +>ISubject : ISubject +>Bar : Bar + +values = values2; +>values = values2 : ISubject +>values : IObservable +>values2 : ISubject + diff --git a/tests/baselines/reference/checkInfiniteExpansionTermination2.js b/tests/baselines/reference/checkInfiniteExpansionTermination2.js new file mode 100644 index 00000000000..6175b34e522 --- /dev/null +++ b/tests/baselines/reference/checkInfiniteExpansionTermination2.js @@ -0,0 +1,27 @@ +//// [checkInfiniteExpansionTermination2.ts] +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; +} +interface ISubject extends IObservable { } + +declare function combineLatest(x: IObservable[]): void; +declare function combineLatest(): void; + +function fn() { + var values: ISubject[] = []; + // Hang when using , but not + combineLatest(values); +} + + +//// [checkInfiniteExpansionTermination2.js] +// Regression test for #1002 +// Before fix this code would cause infinite loop +function fn() { + var values = []; + // Hang when using , but not + combineLatest(values); +} diff --git a/tests/baselines/reference/checkInfiniteExpansionTermination2.types b/tests/baselines/reference/checkInfiniteExpansionTermination2.types new file mode 100644 index 00000000000..fc81e1c9304 --- /dev/null +++ b/tests/baselines/reference/checkInfiniteExpansionTermination2.types @@ -0,0 +1,46 @@ +=== tests/cases/compiler/checkInfiniteExpansionTermination2.ts === +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { +>IObservable : IObservable +>T : T + + n: IObservable; +>n : IObservable +>IObservable : IObservable +>T : T +} +interface ISubject extends IObservable { } +>ISubject : ISubject +>T : T +>IObservable : IObservable +>T : T + +declare function combineLatest(x: IObservable[]): void; +>combineLatest : { (x: IObservable[]): void; (): void; } +>TOther : TOther +>x : IObservable[] +>IObservable : IObservable +>TOther : TOther + +declare function combineLatest(): void; +>combineLatest : { (x: IObservable[]): void; (): void; } + +function fn() { +>fn : () => void +>T : T + + var values: ISubject[] = []; +>values : ISubject[] +>ISubject : ISubject +>[] : undefined[] + + // Hang when using , but not + combineLatest(values); +>combineLatest(values) : void +>combineLatest : { (x: IObservable[]): void; (): void; } +>T : T +>values : ISubject[] +} + diff --git a/tests/baselines/reference/typeComparisonCaching.errors.txt b/tests/baselines/reference/typeComparisonCaching.errors.txt new file mode 100644 index 00000000000..3cbedebb7d2 --- /dev/null +++ b/tests/baselines/reference/typeComparisonCaching.errors.txt @@ -0,0 +1,45 @@ +tests/cases/compiler/typeComparisonCaching.ts(26,1): error TS2323: Type 'B' is not assignable to type 'A'. + Types of property 's' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/typeComparisonCaching.ts(27,1): error TS2323: Type 'D' is not assignable to type 'C'. + Types of property 'q' are incompatible. + Type 'B' is not assignable to type 'A'. + + +==== tests/cases/compiler/typeComparisonCaching.ts (2 errors) ==== + // Check that we only cache results of type comparisons that are free of assumptions + + interface A { + p: C; + s: string; + } + + interface B { + p: D; + s: number; + } + + interface C { + q: A; + } + + interface D { + q: B; + } + + var a: A; + var b: B; + var c: C; + var d: D; + + a = b; + ~ +!!! error TS2323: Type 'B' is not assignable to type 'A'. +!!! error TS2323: Types of property 's' are incompatible. +!!! error TS2323: Type 'number' is not assignable to type 'string'. + c = d; // Should not be allowed + ~ +!!! error TS2323: Type 'D' is not assignable to type 'C'. +!!! error TS2323: Types of property 'q' are incompatible. +!!! error TS2323: Type 'B' is not assignable to type 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/typeComparisonCaching.js b/tests/baselines/reference/typeComparisonCaching.js new file mode 100644 index 00000000000..7d5eb29d52d --- /dev/null +++ b/tests/baselines/reference/typeComparisonCaching.js @@ -0,0 +1,38 @@ +//// [typeComparisonCaching.ts] +// Check that we only cache results of type comparisons that are free of assumptions + +interface A { + p: C; + s: string; +} + +interface B { + p: D; + s: number; +} + +interface C { + q: A; +} + +interface D { + q: B; +} + +var a: A; +var b: B; +var c: C; +var d: D; + +a = b; +c = d; // Should not be allowed + + +//// [typeComparisonCaching.js] +// Check that we only cache results of type comparisons that are free of assumptions +var a; +var b; +var c; +var d; +a = b; +c = d; // Should not be allowed diff --git a/tests/cases/compiler/checkInfiniteExpansionTermination.ts b/tests/cases/compiler/checkInfiniteExpansionTermination.ts new file mode 100644 index 00000000000..8514ebce966 --- /dev/null +++ b/tests/cases/compiler/checkInfiniteExpansionTermination.ts @@ -0,0 +1,16 @@ +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; // Needed, must be T[] +} + +// Needed +interface ISubject extends IObservable { } + +interface Foo { x } +interface Bar { y } + +var values: IObservable; +var values2: ISubject; +values = values2; diff --git a/tests/cases/compiler/checkInfiniteExpansionTermination2.ts b/tests/cases/compiler/checkInfiniteExpansionTermination2.ts new file mode 100644 index 00000000000..f30499ba540 --- /dev/null +++ b/tests/cases/compiler/checkInfiniteExpansionTermination2.ts @@ -0,0 +1,16 @@ +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; +} +interface ISubject extends IObservable { } + +declare function combineLatest(x: IObservable[]): void; +declare function combineLatest(): void; + +function fn() { + var values: ISubject[] = []; + // Hang when using , but not + combineLatest(values); +} diff --git a/tests/cases/compiler/typeComparisonCaching.ts b/tests/cases/compiler/typeComparisonCaching.ts new file mode 100644 index 00000000000..b47d35c60b6 --- /dev/null +++ b/tests/cases/compiler/typeComparisonCaching.ts @@ -0,0 +1,27 @@ +// Check that we only cache results of type comparisons that are free of assumptions + +interface A { + p: C; + s: string; +} + +interface B { + p: D; + s: number; +} + +interface C { + q: A; +} + +interface D { + q: B; +} + +var a: A; +var b: B; +var c: C; +var d: D; + +a = b; +c = d; // Should not be allowed