Skip to content

Commit 9a53243

Browse files
committed
Merge pull request microsoft#330 from Microsoft/pullContextualTypes
Pull model for contextual types
2 parents 93e617a + 2b26e37 commit 9a53243

8 files changed

+397
-243
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module ts {
252252

253253
function bindCatchVariableDeclaration(node: CatchBlock) {
254254
var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing");
255-
addDeclarationToSymbol(symbol, node.variable, SymbolFlags.Variable);
255+
addDeclarationToSymbol(symbol, node, SymbolFlags.Variable);
256256
var saveParent = parent;
257257
parent = node;
258258
forEachChild(node, bind);

src/compiler/checker.ts

Lines changed: 361 additions & 226 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ module ts {
320320
text: string;
321321
}
322322

323-
export interface Expression extends Node { }
323+
export interface Expression extends Node {
324+
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
325+
}
324326

325327
export interface UnaryExpression extends Expression {
326328
operator: SyntaxKind;
@@ -736,17 +738,18 @@ module ts {
736738
}
737739

738740
export enum NodeCheckFlags {
739-
TypeChecked = 0x00000001, // Node has been type checked
740-
LexicalThis = 0x00000002, // Lexical 'this' reference
741-
CaptureThis = 0x00000004, // Lexical 'this' used in body
742-
EmitExtends = 0x00000008, // Emit __extends
743-
SuperInstance = 0x00000010, // Instance 'super' reference
744-
SuperStatic = 0x00000020, // Static 'super' reference
741+
TypeChecked = 0x00000001, // Node has been type checked
742+
LexicalThis = 0x00000002, // Lexical 'this' reference
743+
CaptureThis = 0x00000004, // Lexical 'this' used in body
744+
EmitExtends = 0x00000008, // Emit __extends
745+
SuperInstance = 0x00000010, // Instance 'super' reference
746+
SuperStatic = 0x00000020, // Static 'super' reference
747+
ContextChecked = 0x00000040, // Contextual types have been assigned
745748
}
746749

747750
export interface NodeLinks {
748751
resolvedType?: Type; // Cached type of type node
749-
resolvedSignature?: Signature; // Cached signature of signature node
752+
resolvedSignature?: Signature; // Cached signature of signature node or call expression
750753
resolvedSymbol?: Symbol; // Cached name resolution result
751754
flags?: NodeCheckFlags; // Set of flags specific to Node
752755
enumMemberValue?: number; // Constant value of enum member

tests/baselines/reference/functionImplementationErrors.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/functions/functionImplementationErrors.ts (7 errors) ====
1+
==== tests/cases/conformance/functions/functionImplementationErrors.ts (8 errors) ====
22
// FunctionExpression with no return type annotation with multiple return statements with unrelated types
33
var f1 = function () {
44
~~~~~~~~~~~~~
@@ -68,6 +68,8 @@
6868
// FunctionExpression with non -void return type annotation with a throw, no return, and other code
6969
// Should be error but isn't
7070
undefined === function (): number {
71+
~~~~~~
72+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
7173
throw undefined;
7274
var x = 4;
7375
};

tests/baselines/reference/implicitAnyGetAndSetAccessorWithAnyReturnType.errors.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts (9 errors) ====
1+
==== tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts (8 errors) ====
22
// these should be errors
33
class GetAndSet {
44
getAndSet = null; // error at "getAndSet"
@@ -14,8 +14,6 @@
1414
public set haveGetAndSet(value) { // error at "value"
1515
~~~~~~~~~~~~~
1616
!!! Accessors are only available when targeting ECMAScript 5 and higher.
17-
~~~~~
18-
!!! Parameter 'value' implicitly has an 'any' type.
1917
this.getAndSet = value;
2018
}
2119
}

tests/baselines/reference/parserCastVersusArrowFunction1.errors.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
==== tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunction1.ts (7 errors) ====
1+
==== tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunction1.ts (13 errors) ====
22
var v = <T>() => 1;
33
var v = <T>a;
44
~
55
!!! Cannot find name 'T'.
6+
~
7+
!!! Cannot find name 'a'.
68

79
var v = <T>(a) => 1;
810
~
@@ -17,9 +19,19 @@
1719
var v = <T>(a);
1820
~
1921
!!! Cannot find name 'T'.
22+
~
23+
!!! Cannot find name 'a'.
2024
var v = <T>(a, b);
2125
~
2226
!!! Cannot find name 'T'.
27+
~
28+
!!! Cannot find name 'a'.
29+
~
30+
!!! Cannot find name 'b'.
2331
var v = <T>(a = 1, b = 2);
2432
~
25-
!!! Cannot find name 'T'.
33+
!!! Cannot find name 'T'.
34+
~
35+
!!! Cannot find name 'a'.
36+
~
37+
!!! Cannot find name 'b'.

tests/baselines/reference/parserRealSource8.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/parser/ecmascript5/parserRealSource8.ts (133 errors) ====
1+
==== tests/cases/conformance/parser/ecmascript5/parserRealSource8.ts (134 errors) ====
22
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0.
33
// See LICENSE.txt in the project root for complete license information.
44

@@ -383,6 +383,8 @@
383383
outerFnc.type.members = (<SymbolScopeBuilder>(<TypeSymbol>container).type.memberScope).valueMembers;
384384
~~~~~~~~~~~~~~~~~~
385385
!!! Cannot find name 'SymbolScopeBuilder'.
386+
~~~~~~~~~~
387+
!!! Cannot find name 'TypeSymbol'.
386388
}
387389
funcScope = context.scopeChain.fnc.type.memberScope;
388390
outerFnc.innerStaticFuncs[outerFnc.innerStaticFuncs.length] = funcDecl;

tests/baselines/reference/parserVariableDeclaration3.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration3.ts (3 errors) ====
1+
==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration3.ts (4 errors) ====
22
function runTests() {
33
var outfile = new Harness.Compiler.WriterAggregator()
44
~~~~~~~
@@ -8,6 +8,8 @@
88
!!! Cannot find name 'Harness'.
99
, compiler = <TypeScript.TypeScriptCompiler>new TypeScript.TypeScriptCompiler(outerr)
1010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11+
!!! Cannot find name 'TypeScript'.
12+
~~~~~~~~~~
1113
!!! Cannot find name 'TypeScript'.
1214
, code;
1315
}

0 commit comments

Comments
 (0)