diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 00000000000..164fb69ee20 --- /dev/null +++ b/doc/README.md @@ -0,0 +1,7 @@ +This directory contains miscellaneous documentation such as the TypeScript language specification and logo. +If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook). + +# Spec Contributions + +The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats. +Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests. \ No newline at end of file diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57fd03be9f2..7a98a76a8ac 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -161,6 +161,8 @@ namespace ts { let jsxElementClassType: Type; + let deferredNodes: Node[]; + const tupleTypes: Map = {}; const unionTypes: Map = {}; const intersectionTypes: Map = {}; @@ -5064,6 +5066,11 @@ namespace ts { 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.Enum && target.flags & TypeFlags.Enum) { + if (result = enumRelatedTo(source, target)) { + return result; + } + } if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { if (isTypeAny(source)) return Ternary.True; @@ -5778,6 +5785,27 @@ namespace ts { } return Ternary.False; } + + function enumRelatedTo(source: Type, target: Type) { + if (source.symbol.name !== target.symbol.name || + source.symbol.flags & SymbolFlags.ConstEnum || + target.symbol.flags & SymbolFlags.ConstEnum) { + return Ternary.False; + } + const targetEnumType = getTypeOfSymbol(target.symbol); + for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { + if (property.flags & SymbolFlags.EnumMember) { + const targetProperty = getPropertyOfType(targetEnumType, property.name); + if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { + reportError(Diagnostics.Property_0_is_missing_in_type_1, + property.name, + typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); + return Ternary.False; + } + } + } + return Ternary.True; + } } // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case @@ -6983,17 +7011,11 @@ namespace ts { let needToCaptureLexicalThis = false; if (container.kind === SyntaxKind.Constructor) { - // Keep track of whether we have seen "super" before encounter "this" so that - // we can report appropriate error later in checkConstructorDeclaration - // We have to do the check here to make sure we won't give false error when - // "this" is used in arrow functions - // For example: - // constructor() { - // (()=>this); // No Error - // super(); - // } - const nodeLinks = getNodeLinks(container); - nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; + const baseTypeNode = getClassExtendsHeritageClauseElement(container.parent); + if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) { + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + } } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9799,10 +9821,7 @@ namespace ts { const containgFunction = getContainingFunction(node.expression); if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - const nodeLinks = getNodeLinks(containgFunction); - if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { - nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; - } + getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall; } return voidType; } @@ -10178,6 +10197,7 @@ namespace ts { if (!contextChecked) { checkSignatureDeclaration(node); + checkNodeDeferred(node); } } } @@ -10190,7 +10210,7 @@ namespace ts { return type; } - function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) { + function checkFunctionExpressionOrObjectLiteralMethodDeferred(node: ArrowFunction | FunctionExpression | MethodDeclaration) { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); const isAsync = isAsyncFunctionLike(node); @@ -10233,8 +10253,6 @@ namespace ts { checkTypeAssignableTo(exprType, returnOrPromisedType, node.body); } } - - checkFunctionAndClassExpressionBodies(node.body); } } } @@ -11431,10 +11449,6 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)) { - // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); - } } else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); @@ -11493,13 +11507,13 @@ namespace ts { if (node.parent.kind !== SyntaxKind.ObjectLiteralExpression) { checkSourceElement(node.body); } + else { + checkNodeDeferred(node); + } } - function checkObjectLiteralAccessorBody(node: AccessorDeclaration) { - if (node.body) { - checkSourceElement(node.body); - checkFunctionAndClassExpressionBodies(node.body); - } + function checkAccessorDeferred(node: AccessorDeclaration) { + checkSourceElement(node.body); } function checkMissingDeclaration(node: Node) { @@ -12438,11 +12452,7 @@ namespace ts { if (node.kind === SyntaxKind.Block) { checkGrammarStatementInAmbientContext(node); } - forEach(node.statements, checkSourceElement); - if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) { - checkFunctionAndClassExpressionBodies(node); - } } function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { @@ -13471,15 +13481,19 @@ namespace ts { function checkClassExpression(node: ClassExpression): Type { checkClassLikeDeclaration(node); + checkNodeDeferred(node); return getTypeOfSymbol(getSymbolOfNode(node)); } + function checkClassExpressionDeferred(node: ClassExpression) { + forEach(node.members, checkSourceElement); + } + function checkClassDeclaration(node: ClassDeclaration) { if (!node.name && !(node.flags & NodeFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } checkClassLikeDeclaration(node); - forEach(node.members, checkSourceElement); } @@ -14543,107 +14557,29 @@ namespace ts { // Here, performing a full type check of the body of the function expression whilst in the process of // determining the type of foo would cause foo to be given type any because of the recursive reference. // Delaying the type check of the body ensures foo has been assigned a type. - function checkFunctionAndClassExpressionBodies(node: Node): void { - switch (node.kind) { - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - checkFunctionExpressionOrObjectLiteralMethodBody(node); - break; - case SyntaxKind.ClassExpression: - forEach((node).members, checkSourceElement); - forEachChild(node, checkFunctionAndClassExpressionBodies); - break; - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - forEach(node.decorators, checkFunctionAndClassExpressionBodies); - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - if (isObjectLiteralMethod(node)) { - checkFunctionExpressionOrObjectLiteralMethodBody(node); - } - break; - case SyntaxKind.Constructor: - case SyntaxKind.FunctionDeclaration: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - break; - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) { - checkObjectLiteralAccessorBody(node); - } - break; - case SyntaxKind.WithStatement: - checkFunctionAndClassExpressionBodies((node).expression); - break; - case SyntaxKind.Decorator: - case SyntaxKind.Parameter: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.BindingElement: - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.PropertyAssignment: - case SyntaxKind.PropertyAccessExpression: - case SyntaxKind.ElementAccessExpression: - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.TaggedTemplateExpression: - case SyntaxKind.TemplateExpression: - case SyntaxKind.TemplateSpan: - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.TypeOfExpression: - case SyntaxKind.VoidExpression: - case SyntaxKind.AwaitExpression: - case SyntaxKind.DeleteExpression: - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.PostfixUnaryExpression: - case SyntaxKind.BinaryExpression: - case SyntaxKind.ConditionalExpression: - case SyntaxKind.SpreadElementExpression: - case SyntaxKind.YieldExpression: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.VariableStatement: - case SyntaxKind.ExpressionStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.ContinueStatement: - case SyntaxKind.BreakStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseBlock: - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - case SyntaxKind.LabeledStatement: - case SyntaxKind.ThrowStatement: - case SyntaxKind.TryStatement: - case SyntaxKind.CatchClause: - case SyntaxKind.VariableDeclaration: - case SyntaxKind.VariableDeclarationList: - case SyntaxKind.ClassDeclaration: - case SyntaxKind.HeritageClause: - case SyntaxKind.ExpressionWithTypeArguments: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.EnumMember: - case SyntaxKind.ExportAssignment: - case SyntaxKind.SourceFile: - case SyntaxKind.JsxExpression: - case SyntaxKind.JsxElement: - case SyntaxKind.JsxSelfClosingElement: - case SyntaxKind.JsxAttribute: - case SyntaxKind.JsxSpreadAttribute: - case SyntaxKind.JsxOpeningElement: - forEachChild(node, checkFunctionAndClassExpressionBodies); - break; + function checkNodeDeferred(node: Node) { + if (deferredNodes) { + deferredNodes.push(node); + } + } + + function checkDeferredNodes() { + for (const node of deferredNodes) { + switch (node.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + checkFunctionExpressionOrObjectLiteralMethodDeferred(node); + break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + checkAccessorDeferred(node); + break; + case SyntaxKind.ClassExpression: + checkClassExpressionDeferred(node); + break; + } } } @@ -14678,8 +14614,10 @@ namespace ts { emitAwaiter = false; potentialThisCollisions.length = 0; + deferredNodes = []; forEach(node.statements, checkSourceElement); - checkFunctionAndClassExpressionBodies(node); + checkDeferredNodes(); + deferredNodes = undefined; if (isExternalOrCommonJsModule(node)) { checkExternalModuleExports(node); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a334340fbe1..a0b23e3df59 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2057,8 +2057,7 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure - HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if 'super' is used before 'this' in constructor function - HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' + HasSeenSuperCall = 0x00040000, // Set during the binding when encounter 'super' } /* @internal */ diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index f52ba4b3dbd..0b4e9fd61b1 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,15 +1,18 @@ tests/cases/compiler/baseCheck.ts(9,18): error TS2304: Cannot find name 'loc'. tests/cases/compiler/baseCheck.ts(17,53): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/baseCheck.ts(17,59): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(17,59): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(18,62): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(18,62): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/compiler/baseCheck.ts(19,68): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(19,68): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/baseCheck.ts (9 errors) ==== +==== tests/cases/compiler/baseCheck.ts (12 errors) ==== class C { constructor(x: number, y: number) { } } class ELoc extends C { constructor(x: number) { @@ -33,14 +36,20 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. !!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class E extends C { constructor(public z: number) { super(0, this.z) } } ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type ~~~~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { if (x<10) { diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index c03a47d7532..7c48c977b2d 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -4,6 +4,7 @@ tests/cases/compiler/bases.ts(7,17): error TS2304: Cannot find name 'any'. tests/cases/compiler/bases.ts(11,7): error TS2420: Class 'C' incorrectly implements interface 'I'. Property 'x' is missing in type 'C'. tests/cases/compiler/bases.ts(12,5): error TS2377: Constructors for derived classes must contain a 'super' call. +tests/cases/compiler/bases.ts(13,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/bases.ts(13,14): error TS2339: Property 'x' does not exist on type 'C'. tests/cases/compiler/bases.ts(13,15): error TS1005: ';' expected. tests/cases/compiler/bases.ts(13,17): error TS2304: Cannot find name 'any'. @@ -11,7 +12,7 @@ tests/cases/compiler/bases.ts(17,9): error TS2339: Property 'x' does not exist o tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. -==== tests/cases/compiler/bases.ts (10 errors) ==== +==== tests/cases/compiler/bases.ts (11 errors) ==== interface I { x; } @@ -36,6 +37,8 @@ tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist o ~~~~~~~~~~~~~~~ this.x: any; ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ~ !!! error TS2339: Property 'x' does not exist on type 'C'. ~ diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js index ec6e6e39ee8..cfb5726dac1 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index e48f43c8662..c8aa356fd4f 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -7,9 +7,9 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: public x: number; constructor() { this.x = 100; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js index eb58afd820b..afbc15cf912 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js index 2c5652cf95f..7e9c23c1f83 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -25,7 +25,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -34,10 +34,10 @@ var Derived = (function (_super) { this.y = true; } return innver; - })(); + }()); _super.call(this); this.x = 10; var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js index eacec00c438..1257b446ccb 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -29,7 +29,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -49,4 +49,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index 1258101cffc..8ffed5961a3 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: public x: number; constructor() { super(this.x); - ~~~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js index 489c7200050..1889ee998ca 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -21,11 +21,11 @@ var Based = (function () { } } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { _super.call(this, this.x); } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js index 6ad9773bc5f..39db4dec174 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -33,4 +33,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js index eafc662085f..d071c05db5d 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -19,7 +19,7 @@ var Base = (function () { function Base(func) { } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -27,4 +27,4 @@ var Super = (function (_super) { _super.call(this, (function () { return _this; })); // No error } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index 7a00a4f0130..2b37f740331 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(7,20): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -9,8 +9,8 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: class Super extends Base { constructor() { var that = this; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js index 4675d328b38..f334cc7f42b 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -32,4 +32,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 37f272db082..c54ef2a02b7 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,11 +1,15 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (5 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -57,10 +61,10 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a: number; constructor(y: string) { this.a = 1; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. var b = 2; super(); // error: "super" has to be called before "this" accessing - ~~~~~~~~ -!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -69,7 +73,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. @@ -94,7 +102,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index 0190a659166..7439c81be85 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,9 +1,10 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (3 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (4 errors) ==== class Base { x: string; constructor(a) { } @@ -12,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +23,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt new file mode 100644 index 00000000000..02cb4314777 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. + Property 'c' is missing in type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. + Property 'a' is missing in type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(77,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(82,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(83,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. + + +==== tests/cases/compiler/enumAssignmentCompat3.ts (9 errors) ==== + namespace First { + export enum E { + a, b, c, + } + } + namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } + } + namespace Abcd { + export enum E { + a, b, c, d, + } + } + namespace Ab { + export enum E { + a, b, + } + } + namespace Cd { + export enum E { + c, d, + } + } + namespace Const { + export const enum E { + a, b, c, + } + } + namespace Decl { + export declare enum E { + a, b, c = 3, + } + } + namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } + } + + namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } + } + + var abc: First.E; + var secondAbc: Abc.E; + var secondAbcd: Abcd.E; + var secondAb: Ab.E; + var secondCd: Cd.E; + var nope: Abc.Nope; + var k: Const.E; + var decl: Decl.E; + var merged: Merged.E; + var merged2: Merged2.E; + abc = secondAbc; // ok + abc = secondAbcd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = secondAb; // ok + abc = secondCd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = nope; // nope! + ~~~ +!!! error TS2322: Type 'Nope' is not assignable to type 'E'. + abc = decl; // ok + secondAbc = abc; // ok + secondAbcd = abc; // ok + secondAb = abc; // missing 'c' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +!!! error TS2322: Property 'c' is missing in type 'Ab.E'. + secondCd = abc; // missing 'a' and 'b' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +!!! error TS2322: Property 'a' is missing in type 'Cd.E'. + nope = abc; // nope! + ~~~~ +!!! error TS2322: Type 'E' is not assignable to type 'Nope'. + decl = abc; // ok + + // const is only assignable to itself + k = k; + abc = k; // error + ~~~ +!!! error TS2322: Type 'Const.E' is not assignable to type 'First.E'. + k = abc; + ~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Const.E'. + + // merged enums compare all their members + abc = merged; // missing 'd' + ~~~ +!!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + merged = abc; // ok + abc = merged2; // ok + merged2 = abc; // ok \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js new file mode 100644 index 00000000000..74f74ab1652 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -0,0 +1,202 @@ +//// [enumAssignmentCompat3.ts] +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} + +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; +var merged: Merged.E; +var merged2: Merged2.E; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok + +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok + +//// [enumAssignmentCompat3.js] +var First; +(function (First) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(First.E || (First.E = {})); + var E = First.E; +})(First || (First = {})); +var Abc; +(function (Abc) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Abc.E || (Abc.E = {})); + var E = Abc.E; + (function (Nope) { + Nope[Nope["a"] = 0] = "a"; + Nope[Nope["b"] = 1] = "b"; + Nope[Nope["c"] = 2] = "c"; + })(Abc.Nope || (Abc.Nope = {})); + var Nope = Abc.Nope; +})(Abc || (Abc = {})); +var Abcd; +(function (Abcd) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + E[E["d"] = 3] = "d"; + })(Abcd.E || (Abcd.E = {})); + var E = Abcd.E; +})(Abcd || (Abcd = {})); +var Ab; +(function (Ab) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Ab.E || (Ab.E = {})); + var E = Ab.E; +})(Ab || (Ab = {})); +var Cd; +(function (Cd) { + (function (E) { + E[E["c"] = 0] = "c"; + E[E["d"] = 1] = "d"; + })(Cd.E || (Cd.E = {})); + var E = Cd.E; +})(Cd || (Cd = {})); +var Decl; +(function (Decl) { +})(Decl || (Decl = {})); +var Merged; +(function (Merged) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; + (function (E) { + E[E["c"] = 3] = "c"; + E[E["d"] = 4] = "d"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; +})(Merged || (Merged = {})); +var Merged2; +(function (Merged2) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Merged2.E || (Merged2.E = {})); + var E = Merged2.E; + var E; + (function (E) { + E.d = 5; + })(E = Merged2.E || (Merged2.E = {})); +})(Merged2 || (Merged2 = {})); +var abc; +var secondAbc; +var secondAbcd; +var secondAb; +var secondCd; +var nope; +var k; +var decl; +var merged; +var merged2; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt index abf11dc9dba..48a1da7d22c 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -1,20 +1,11 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'. -==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ==== +==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (1 errors) ==== return this.edit(role) ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. - ~~~~ -!!! error TS2304: Cannot find name 'role'. .then((role: Role) => - ~~~~ -!!! error TS2304: Cannot find name 'Role'. this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg) => data.data)); - ~~ -!!! error TS2503: Cannot find namespace 'ng'. \ No newline at end of file diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js index 2ada9f1bb52..4821f1fe69c 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js @@ -6,9 +6,8 @@ return this.edit(role) //// [multiLinePropertyAccessAndArrowFunctionIndent1.js] -var _this = this; return this.edit(role) .then(function (role) { - return _this.roleService.add(role) + return this.roleService.add(role) .then(function (data) { return data.data; }); }); diff --git a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt index 72cfee58e54..0532fd28d63 100644 --- a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt +++ b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(6,5): error TS2304: Cannot find name 'private'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (1 errors) ==== return { ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. @@ -11,8 +10,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMe // 'private' should not be considered a member variable here. private[key] = value; - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index d74db892019..ccf6a015bd9 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -8,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -25,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): //'this' in optional super call constructor() { super(this); // Error - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -37,6 +38,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 89472de5d1a..bc671b2fdbe 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -9,7 +10,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (10 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -26,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod //'this' in optional super call constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -38,6 +39,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index f0fc5854123..000c2074892 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (5 errors) ==== class Base { constructor(x: any) {} } @@ -11,7 +13,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r class Foo extends Base { constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +24,8 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -30,5 +34,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall1.errors.txt b/tests/baselines/reference/thisInSuperCall1.errors.txt index 7efc66d1666..98d8ee123ae 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall1.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -11,6 +12,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 11ea23d020c..4047bcb9a06 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,8 +1,9 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (3 errors) ==== class Base { constructor(a: any) {} } @@ -11,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be public x: number; constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -23,6 +24,8 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index df5c5f8b5a2..0e7d1575096 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall3.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -13,6 +14,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts new file mode 100644 index 00000000000..97a136468e3 --- /dev/null +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -0,0 +1,89 @@ +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} + +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; +var merged: Merged.E; +var merged2: Merged2.E; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok + +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok \ No newline at end of file