Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use literal types #10676

Merged
merged 36 commits into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b96f6cd
Union type instead of best common supertype for multiple return state…
ahejlsberg Sep 1, 2016
b5c2d5b
Accept new baselines
ahejlsberg Sep 1, 2016
a8063df
Always use literal types for literals
ahejlsberg Sep 1, 2016
adc015d
Always keep literal types and widen when inferred as types for mutabl…
ahejlsberg Sep 1, 2016
44e1096
Update tests
ahejlsberg Sep 1, 2016
33b8109
Accept new baselines (huge!)
ahejlsberg Sep 1, 2016
cf55bf9
Fix lint errors
ahejlsberg Sep 1, 2016
feeb204
Fix fourslash tests
ahejlsberg Sep 1, 2016
2a60f79
Remove failing fourslash tests (may need to be restored and fixed)
ahejlsberg Sep 1, 2016
b3c9571
Restrict widening of literal types in type argument inference
ahejlsberg Sep 2, 2016
6ae71cb
Readonly properties in classes are considered immutable locations
ahejlsberg Sep 2, 2016
b10f79b
Keep literal return types only when contextually typed by type contai…
ahejlsberg Sep 2, 2016
4b9b90a
Perform return type widening checks after union type is formed
ahejlsberg Sep 2, 2016
db230a2
Accept new baselines
ahejlsberg Sep 2, 2016
694705f
Removing old comment
ahejlsberg Sep 2, 2016
ff3b627
Less widening of literal types in type inference
ahejlsberg Sep 7, 2016
da2efa0
Accept new baselines
ahejlsberg Sep 7, 2016
2f9c9c9
Remove failing fourslash tests (may need to be restored and fixed)
ahejlsberg Sep 7, 2016
b33e499
Merge branch 'master' into literalTypesAlways
ahejlsberg Sep 7, 2016
ad1c9b9
Fix merge issue
ahejlsberg Sep 7, 2016
b9fa0af
Fixing the fix
ahejlsberg Sep 7, 2016
737867e
Accept new baselines
ahejlsberg Sep 7, 2016
31a94fc
Cleaning up InferenceContext
ahejlsberg Sep 7, 2016
6f06d06
Simplify tracking of top-level type inferences
ahejlsberg Sep 7, 2016
56c37ec
Merge branch 'master' into literalTypesAlways
mhegazy Sep 7, 2016
d6de3e1
Revert "Remove failing fourslash tests (may need to be restored and f…
mhegazy Sep 8, 2016
f73b4be
Revert "Remove failing fourslash tests (may need to be restored and f…
mhegazy Sep 8, 2016
05882ff
Merge branch 'useBaselinesForQuickInfoTests' into literalTypesAlways
mhegazy Sep 8, 2016
f13c16d
Fix tests
mhegazy Sep 8, 2016
dfb5091
Merge branch 'master' into literalTypesAlways
mhegazy Sep 8, 2016
090c2fe
Accept baselines after merge
mhegazy Sep 8, 2016
3ea1b79
Fix fourslash test
mhegazy Sep 8, 2016
aeb899a
Merge branch 'master' into literalTypesAlways
ahejlsberg Sep 11, 2016
a28c703
Accept new baselines
ahejlsberg Sep 11, 2016
2344a80
Handle const binding elements with initializers correctly
ahejlsberg Sep 11, 2016
ef81594
Add tests
ahejlsberg Sep 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ namespace ts {
case SyntaxKind.PrefixUnaryExpression:
bindPrefixUnaryExpressionFlow(<PrefixUnaryExpression>node);
break;
case SyntaxKind.PostfixUnaryExpression:
bindPostfixUnaryExpressionFlow(<PostfixUnaryExpression>node);
break;
case SyntaxKind.BinaryExpression:
bindBinaryExpressionFlow(<BinaryExpression>node);
break;
Expand Down Expand Up @@ -1106,6 +1109,16 @@ namespace ts {
}
else {
forEachChild(node, bind);
if (node.operator === SyntaxKind.PlusEqualsToken || node.operator === SyntaxKind.MinusMinusToken) {
bindAssignmentTargetFlow(node.operand);
}
}
}

function bindPostfixUnaryExpressionFlow(node: PostfixUnaryExpression) {
forEachChild(node, bind);
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
bindAssignmentTargetFlow(node.operand);
}
}

Expand Down
256 changes: 123 additions & 133 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,6 @@
"category": "Error",
"code": 2353
},
"No best common type exists among return expressions.": {
"category": "Error",
"code": 2354
},
"A function whose declared type is neither 'void' nor 'any' must return a value.": {
"category": "Error",
"code": 2355
Expand Down Expand Up @@ -1631,10 +1627,6 @@
"category": "Error",
"code": 2503
},
"No best common type exists among yield expressions.": {
"category": "Error",
"code": 2504
},
"A generator cannot have a 'void' type annotation.": {
"category": "Error",
"code": 2505
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2593,13 +2593,14 @@ namespace ts {
export interface TypeInferences {
primary: Type[]; // Inferences made directly to a type parameter
secondary: Type[]; // Inferences made to a type parameter in a union type
topLevel: boolean; // True if all inferences were made from top-level (not nested in object type) locations
isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec
// If a type parameter is fixed, no more inferences can be made for the type parameter
}

/* @internal */
export interface InferenceContext {
typeParameters: TypeParameter[]; // Type parameters for which inferences are made
signature: Signature; // Generic signature for which inferences are made
inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType)
inferences: TypeInferences[]; // Inferences made for each type parameter
inferredTypes: Type[]; // Inferred type for each type parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
>A.Point : typeof A.Point
>A : typeof A
>Point : typeof A.Point
>0 : number
>0 : number
>0 : 0
>0 : 0

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
>A.Point : typeof A.Point
>A : typeof A
>Point : typeof A.Point
>0 : number
>0 : number
>0 : 0
>0 : 0

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function Point() {
return { x: 0, y: 0 };
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : number
>0 : 0
>y : number
>0 : number
>0 : 0
}

=== tests/cases/conformance/internalModules/DeclarationMerging/test.ts ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class Point {
>Point : Point
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : number
>0 : 0
>y : number
>0 : number
>0 : 0
}

module Point {
>Point : typeof Point

function Origin() { return ""; }// not an error, since not exported
>Origin : () => string
>"" : string
>"" : ""
}


Expand All @@ -40,16 +40,16 @@ module A {
>Point : Point
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : number
>0 : 0
>y : number
>0 : number
>0 : 0
}

export module Point {
>Point : typeof Point

function Origin() { return ""; }// not an error since not exported
>Origin : () => string
>"" : string
>"" : ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class Point {
>Point : Point
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : number
>0 : 0
>y : number
>0 : number
>0 : 0
}

module Point {
>Point : typeof Point

var Origin = ""; // not an error, since not exported
>Origin : string
>"" : string
>"" : ""
}


Expand All @@ -40,16 +40,16 @@ module A {
>Point : Point
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : number
>0 : 0
>y : number
>0 : number
>0 : 0
}

export module Point {
>Point : typeof Point

var Origin = ""; // not an error since not exported
>Origin : string
>"" : string
>"" : ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class C {

x = 10;
>x : number
>10 : number
>10 : 10
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES3For-ofTypeCheck2.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
for (var v of [true]) { }
>v : boolean
>[true] : boolean[]
>true : boolean
>true : true

2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of10.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function foo() {
return { x: 0 };
>{ x: 0 } : { x: number; }
>x : number
>0 : number
>0 : 0
}
for (foo().x of []) {
>foo().x : number
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/ES5For-of13.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
for (let v of ['a', 'b', 'c']) {
>v : string
>['a', 'b', 'c'] : string[]
>'a' : string
>'b' : string
>'c' : string
>'a' : "a"
>'b' : "b"
>'c' : "c"

var x = v;
>x : string
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/ES5For-of24.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
var a = [1, 2, 3];
>a : number[]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>1 : 1
>2 : 2
>3 : 3

for (var v of a) {
>v : number
>a : number[]

let a = 0;
>a : number
>0 : number
>0 : 0
}
6 changes: 3 additions & 3 deletions tests/baselines/reference/ES5For-of25.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
var a = [1, 2, 3];
>a : number[]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>1 : 1
>2 : 2
>3 : 3

for (var v of a) {
>v : number
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/ES5For-of3.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
for (var v of ['a', 'b', 'c'])
>v : string
>['a', 'b', 'c'] : string[]
>'a' : string
>'b' : string
>'c' : string
>'a' : "a"
>'b' : "b"
>'c' : "c"

var x = v;
>x : string
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/ES5For-of30.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'string | number' is not an array type.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type '1' is not assignable to type 'string'.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type '""' is not assignable to type 'number'.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts (3 errors) ====
Expand All @@ -10,9 +10,9 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error
~~~~~~~~~~~~~~~
!!! error TS2461: Type 'string | number' is not an array type.
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! error TS2322: Type '1' is not assignable to type 'string'.
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! error TS2322: Type '""' is not assignable to type 'number'.
a;
b;
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of9.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function foo() {
return { x: 0 };
>{ x: 0 } : { x: number; }
>x : number
>0 : number
>0 : 0
}
for (foo().x of []) {
>foo().x : number
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-ofTypeCheck1.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck1.ts ===
for (var v of "") { }
>v : string
>"" : string
>"" : ""

4 changes: 2 additions & 2 deletions tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2495: Type 'number' is not an array type or a string type.
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2495: Type '0' is not an array type or a string type.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts (1 errors) ====
for (const v of 0) { }
~
!!! error TS2495: Type 'number' is not an array type or a string type.
!!! error TS2495: Type '0' is not an array type or a string type.
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-ofTypeCheck2.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
for (var v of [true]) { }
>v : boolean
>[true] : boolean[]
>true : boolean
>true : true

4 changes: 2 additions & 2 deletions tests/baselines/reference/ES5For-ofTypeCheck3.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
var tuple: [string, number] = ["", 0];
>tuple : [string, number]
>["", 0] : [string, number]
>"" : string
>0 : number
>"" : ""
>0 : 0

for (var v of tuple) { }
>v : string | number
Expand Down
14 changes: 7 additions & 7 deletions tests/baselines/reference/ES5for-of32.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
var array = [1,2,3];
>array : number[]
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
>1 : 1
>2 : 2
>3 : 3

var sum = 0;
>sum : number
>0 : number
>0 : 0

for (let num of array) {
>num : number
Expand All @@ -24,9 +24,9 @@ for (let num of array) {
>array = [4,5,6] : number[]
>array : number[]
>[4,5,6] : number[]
>4 : number
>5 : number
>6 : number
>4 : 4
>5 : 5
>6 : 6
}

sum += num;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ enum enumdule {
>enumdule : enumdule

Red, Blue
>Red : enumdule
>Blue : enumdule
>Red : enumdule.Red
>Blue : enumdule.Blue
}

module enumdule {
Expand All @@ -25,9 +25,9 @@ var x: enumdule;

var x = enumdule.Red;
>x : enumdule
>enumdule.Red : enumdule
>enumdule.Red : enumdule.Red
>enumdule : typeof enumdule
>Red : enumdule
>Red : enumdule.Red

var y: { x: number; y: number };
>y : { x: number; y: number; }
Expand All @@ -40,6 +40,6 @@ var y = new enumdule.Point(0, 0);
>enumdule.Point : typeof enumdule.Point
>enumdule : typeof enumdule
>Point : typeof enumdule.Point
>0 : number
>0 : number
>0 : 0
>0 : 0

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module A {
>Point : Point

return 1;
>1 : number
>1 : 1
}
}
}
Expand Down
Loading