Skip to content

Commit e0f9825

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into fixingTypeParameters
2 parents c7c774d + 742b2ad commit e0f9825

File tree

84 files changed

+1478
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1478
-418
lines changed

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ task("runtests", ["tests", builtLocalDirectory], function() {
566566
colors = process.env.colors || process.env.color
567567
colors = colors ? ' --no-colors ' : ' --colors ';
568568
tests = tests ? ' -g ' + tests : '';
569-
reporter = process.env.reporter || process.env.r || 'dot';
569+
reporter = process.env.reporter || process.env.r || 'mocha-fivemat-progress-reporter';
570570
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
571571
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
572572
var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"chai": "latest",
3535
"browserify": "latest",
3636
"istanbul": "latest",
37+
"mocha-fivemat-progress-reporter": "latest",
3738
"tslint": "latest"
3839
},
3940
"scripts": {

src/compiler/checker.ts

+89-39
Original file line numberDiff line numberDiff line change
@@ -3943,7 +3943,7 @@ namespace ts {
39433943
let id = getTypeListId(elementTypes);
39443944
let type = tupleTypes[id];
39453945
if (!type) {
3946-
type = tupleTypes[id] = <TupleType>createObjectType(TypeFlags.Tuple);
3946+
type = tupleTypes[id] = <TupleType>createObjectType(TypeFlags.Tuple | getWideningFlagsOfTypes(elementTypes));
39473947
type.elementTypes = elementTypes;
39483948
}
39493949
return type;
@@ -4906,9 +4906,38 @@ namespace ts {
49064906
let targetSignatures = getSignaturesOfType(target, kind);
49074907
let result = Ternary.True;
49084908
let saveErrorInfo = errorInfo;
4909+
4910+
// Because the "abstractness" of a class is the same across all construct signatures
4911+
// (internally we are checking the corresponding declaration), it is enough to perform
4912+
// the check and report an error once over all pairs of source and target construct signatures.
4913+
let sourceSig = sourceSignatures[0];
4914+
// Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds.
4915+
let targetSig = targetSignatures[0];
4916+
4917+
if (sourceSig && targetSig) {
4918+
let sourceErasedSignature = getErasedSignature(sourceSig);
4919+
let targetErasedSignature = getErasedSignature(targetSig);
4920+
4921+
let sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
4922+
let targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
4923+
4924+
let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getDeclarationOfKind(sourceReturnType.symbol, SyntaxKind.ClassDeclaration);
4925+
let targetReturnDecl = targetReturnType && targetReturnType.symbol && getDeclarationOfKind(targetReturnType.symbol, SyntaxKind.ClassDeclaration);
4926+
let sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
4927+
let targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
4928+
4929+
if (sourceIsAbstract && !targetIsAbstract) {
4930+
if (reportErrors) {
4931+
reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
4932+
}
4933+
return Ternary.False;
4934+
}
4935+
}
4936+
49094937
outer: for (let t of targetSignatures) {
49104938
if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) {
49114939
let localErrors = reportErrors;
4940+
let checkedAbstractAssignability = false;
49124941
for (let s of sourceSignatures) {
49134942
if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) {
49144943
let related = signatureRelatedTo(s, t, localErrors);
@@ -5015,10 +5044,11 @@ namespace ts {
50155044
return Ternary.False;
50165045
}
50175046

5018-
let t = getReturnTypeOfSignature(target);
5019-
if (t === voidType) return result;
5020-
let s = getReturnTypeOfSignature(source);
5021-
return result & isRelatedTo(s, t, reportErrors);
5047+
let targetReturnType = getReturnTypeOfSignature(target);
5048+
if (targetReturnType === voidType) return result;
5049+
let sourceReturnType = getReturnTypeOfSignature(source);
5050+
5051+
return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors);
50225052
}
50235053

50245054
function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary {
@@ -5272,8 +5302,8 @@ namespace ts {
52725302
* Check if a Type was written as a tuple type literal.
52735303
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
52745304
*/
5275-
function isTupleType(type: Type): boolean {
5276-
return (type.flags & TypeFlags.Tuple) && !!(<TupleType>type).elementTypes;
5305+
function isTupleType(type: Type): type is TupleType {
5306+
return !!(type.flags & TypeFlags.Tuple);
52775307
}
52785308

52795309
function getWidenedTypeOfObjectLiteral(type: Type): Type {
@@ -5314,37 +5344,55 @@ namespace ts {
53145344
if (isArrayType(type)) {
53155345
return createArrayType(getWidenedType((<TypeReference>type).typeArguments[0]));
53165346
}
5347+
if (isTupleType(type)) {
5348+
return createTupleType(map(type.elementTypes, getWidenedType));
5349+
}
53175350
}
53185351
return type;
53195352
}
53205353

5354+
/**
5355+
* Reports implicit any errors that occur as a result of widening 'null' and 'undefined'
5356+
* to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to
5357+
* getWidenedType. But in some cases getWidenedType is called without reporting errors
5358+
* (type argument inference is an example).
5359+
*
5360+
* The return value indicates whether an error was in fact reported. The particular circumstances
5361+
* are on a best effort basis. Currently, if the null or undefined that causes widening is inside
5362+
* an object literal property (arbitrarily deeply), this function reports an error. If no error is
5363+
* reported, reportImplicitAnyError is a suitable fallback to report a general error.
5364+
*/
53215365
function reportWideningErrorsInType(type: Type): boolean {
5366+
let errorReported = false;
53225367
if (type.flags & TypeFlags.Union) {
5323-
let errorReported = false;
5324-
forEach((<UnionType>type).types, t => {
5368+
for (let t of (<UnionType>type).types) {
53255369
if (reportWideningErrorsInType(t)) {
53265370
errorReported = true;
53275371
}
5328-
});
5329-
return errorReported;
5372+
}
53305373
}
53315374
if (isArrayType(type)) {
53325375
return reportWideningErrorsInType((<TypeReference>type).typeArguments[0]);
53335376
}
5377+
if (isTupleType(type)) {
5378+
for (let t of type.elementTypes) {
5379+
if (reportWideningErrorsInType(t)) {
5380+
errorReported = true;
5381+
}
5382+
}
5383+
}
53345384
if (type.flags & TypeFlags.ObjectLiteral) {
5335-
let errorReported = false;
5336-
forEach(getPropertiesOfObjectType(type), p => {
5385+
for (let p of getPropertiesOfObjectType(type)) {
53375386
let t = getTypeOfSymbol(p);
53385387
if (t.flags & TypeFlags.ContainsUndefinedOrNull) {
53395388
if (!reportWideningErrorsInType(t)) {
53405389
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
53415390
}
53425391
errorReported = true;
53435392
}
5344-
});
5345-
return errorReported;
5393+
}
53465394
}
5347-
return false;
5395+
return errorReported;
53485396
}
53495397

53505398
function reportImplicitAnyError(declaration: Declaration, type: Type) {
@@ -5513,30 +5561,33 @@ namespace ts {
55135561
inferFromTypes(sourceType, target);
55145562
}
55155563
}
5516-
else if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) ||
5517-
(target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class))) {
5518-
// If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members
5519-
if (isInProcess(source, target)) {
5520-
return;
5521-
}
5522-
if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
5523-
return;
5524-
}
5564+
else {
5565+
source = getApparentType(source);
5566+
if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) ||
5567+
(target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class))) {
5568+
// If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members
5569+
if (isInProcess(source, target)) {
5570+
return;
5571+
}
5572+
if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
5573+
return;
5574+
}
55255575

5526-
if (depth === 0) {
5527-
sourceStack = [];
5528-
targetStack = [];
5576+
if (depth === 0) {
5577+
sourceStack = [];
5578+
targetStack = [];
5579+
}
5580+
sourceStack[depth] = source;
5581+
targetStack[depth] = target;
5582+
depth++;
5583+
inferFromProperties(source, target);
5584+
inferFromSignatures(source, target, SignatureKind.Call);
5585+
inferFromSignatures(source, target, SignatureKind.Construct);
5586+
inferFromIndexTypes(source, target, IndexKind.String, IndexKind.String);
5587+
inferFromIndexTypes(source, target, IndexKind.Number, IndexKind.Number);
5588+
inferFromIndexTypes(source, target, IndexKind.String, IndexKind.Number);
5589+
depth--;
55295590
}
5530-
sourceStack[depth] = source;
5531-
targetStack[depth] = target;
5532-
depth++;
5533-
inferFromProperties(source, target);
5534-
inferFromSignatures(source, target, SignatureKind.Call);
5535-
inferFromSignatures(source, target, SignatureKind.Construct);
5536-
inferFromIndexTypes(source, target, IndexKind.String, IndexKind.String);
5537-
inferFromIndexTypes(source, target, IndexKind.Number, IndexKind.Number);
5538-
inferFromIndexTypes(source, target, IndexKind.String, IndexKind.Number);
5539-
depth--;
55405591
}
55415592
}
55425593

@@ -6949,7 +7000,6 @@ namespace ts {
69497000
}
69507001
}
69517002

6952-
69537003
function checkJsxSelfClosingElement(node: JsxSelfClosingElement) {
69547004
checkJsxOpeningLikeElement(node);
69557005
return jsxElementType || anyType;

src/compiler/diagnosticInformationMap.generated.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ namespace ts {
407407
Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." },
408408
Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." },
409409
All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." },
410-
Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" },
410+
Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." },
411411
Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." },
412412
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
413413
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@
16171617
"category": "Error",
16181618
"code": 2516
16191619
},
1620-
"Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type": {
1620+
"Cannot assign an abstract constructor type to a non-abstract constructor type.": {
16211621
"category": "Error",
16221622
"code":2517
16231623
},

src/compiler/sys.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace ts {
2929
declare var process: any;
3030
declare var global: any;
3131
declare var __filename: string;
32+
declare var Buffer: {
33+
new (str: string, encoding ?: string): any;
34+
}
3235

3336
declare class Enumerator {
3437
public atEnd(): boolean;
@@ -267,10 +270,17 @@ namespace ts {
267270
args: process.argv.slice(2),
268271
newLine: _os.EOL,
269272
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
270-
write(s: string): void {
273+
write(s: string): void {
274+
var buffer = new Buffer(s, 'utf8');
275+
var offset: number = 0;
276+
var toWrite: number = buffer.length;
277+
var written = 0;
271278
// 1 is a standard descriptor for stdout
272-
_fs.writeSync(1, s);
273-
},
279+
while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
280+
offset += written;
281+
toWrite -= written;
282+
}
283+
},
274284
readFile,
275285
writeFile,
276286
watchFile: (fileName, callback) => {

0 commit comments

Comments
 (0)