Skip to content

Commit

Permalink
Merge pull request #10676 from Microsoft/literalTypesAlways
Browse files Browse the repository at this point in the history
Always use literal types
  • Loading branch information
ahejlsberg committed Sep 11, 2016
2 parents 2305c68 + ef81594 commit 3cca17e
Show file tree
Hide file tree
Showing 2,203 changed files with 21,274 additions and 14,155 deletions.
13 changes: 13 additions & 0 deletions src/compiler/binder.ts
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
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
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
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

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

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
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
>"" : ""
}
}
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
>"" : ""
}
}
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
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
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
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
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
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
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
@@ -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
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
@@ -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
@@ -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
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
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
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
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

Expand Up @@ -31,7 +31,7 @@ module A {
>Point : Point

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

0 comments on commit 3cca17e

Please sign in to comment.