-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Local types #3266
Local types #3266
Changes from all commits
af8aefd
375516e
df9378e
cf40696
10e940a
142605c
e053cb8
f957427
5eff0a5
50ebc2b
b28f74e
26b955a
3f99b74
143fd5d
db30e57
a2783ed
f0ac90f
6f734d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,7 +917,7 @@ module ts { | |
_classElementBrand: any; | ||
} | ||
|
||
export interface InterfaceDeclaration extends Declaration, ModuleElement { | ||
export interface InterfaceDeclaration extends Declaration, Statement { | ||
name: Identifier; | ||
typeParameters?: NodeArray<TypeParameterDeclaration>; | ||
heritageClauses?: NodeArray<HeritageClause>; | ||
|
@@ -929,7 +929,7 @@ module ts { | |
types?: NodeArray<ExpressionWithTypeArguments>; | ||
} | ||
|
||
export interface TypeAliasDeclaration extends Declaration, ModuleElement { | ||
export interface TypeAliasDeclaration extends Declaration, Statement { | ||
name: Identifier; | ||
type: TypeNode; | ||
} | ||
|
@@ -941,7 +941,7 @@ module ts { | |
initializer?: Expression; | ||
} | ||
|
||
export interface EnumDeclaration extends Declaration, ModuleElement { | ||
export interface EnumDeclaration extends Declaration, Statement { | ||
name: Identifier; | ||
members: NodeArray<EnumMember>; | ||
} | ||
|
@@ -1626,6 +1626,8 @@ module ts { | |
// Class and interface types (TypeFlags.Class and TypeFlags.Interface) | ||
export interface InterfaceType extends ObjectType { | ||
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) | ||
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none) | ||
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none) | ||
} | ||
|
||
export interface InterfaceTypeWithBaseTypes extends InterfaceType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expected to see things like changes to ClassDeclation/EnumDeclaration/etc. to make them statements. If they're not statements, then we need to change things like Block to have an array of ModuleElements instead. Right now the type system isn't correct vis-a-vis what we say you may encounter and what you can actually encounter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are. You're looking at the type interfaces here, not the node interfaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused. For example, I don't see a change to EnumDeclaration to make it a Statement. As such, i would not expect that it could be contained within a Block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it looks like only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always parse all modifiers on a declaration and then issue errors later during type check. We need to do this so our incremental parsing always parses declarations the same. Also, it provides better error handling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense. Thanks for explaining. |
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=== tests/cases/compiler/classDeclarationBlockScoping1.ts === | ||
class C { | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 0, 0)) | ||
} | ||
|
||
{ | ||
class C { | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 3, 1)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=== tests/cases/compiler/classDeclarationBlockScoping1.ts === | ||
class C { | ||
>C : C | ||
} | ||
|
||
{ | ||
class C { | ||
>C : C | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== tests/cases/compiler/classDeclarationBlockScoping2.ts === | ||
function f() { | ||
>f : Symbol(f, Decl(classDeclarationBlockScoping2.ts, 0, 0)) | ||
|
||
class C {} | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) | ||
|
||
var c1 = C; | ||
>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7)) | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) | ||
{ | ||
class C {} | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5)) | ||
|
||
var c2 = C; | ||
>c2 : Symbol(c2, Decl(classDeclarationBlockScoping2.ts, 5, 11)) | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5)) | ||
} | ||
return C === c1; | ||
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) | ||
>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
=== tests/cases/compiler/classDeclarationBlockScoping2.ts === | ||
function f() { | ||
>f : () => boolean | ||
|
||
class C {} | ||
>C : C | ||
|
||
var c1 = C; | ||
>c1 : typeof C | ||
>C : typeof C | ||
{ | ||
class C {} | ||
>C : C | ||
|
||
var c2 = C; | ||
>c2 : typeof C | ||
>C : typeof C | ||
} | ||
return C === c1; | ||
>C === c1 : boolean | ||
>C : typeof C | ||
>c1 : typeof C | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
=== tests/cases/compiler/classExpressionTest1.ts === | ||
function M() { | ||
>M : Symbol(M, Decl(classExpressionTest1.ts, 0, 0)) | ||
|
||
class C<X> { | ||
>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14)) | ||
>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12)) | ||
|
||
f<T>() { | ||
>f : Symbol(f, Decl(classExpressionTest1.ts, 1, 16)) | ||
>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10)) | ||
|
||
var t: T; | ||
>t : Symbol(t, Decl(classExpressionTest1.ts, 3, 15)) | ||
>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10)) | ||
|
||
var x: X; | ||
>x : Symbol(x, Decl(classExpressionTest1.ts, 4, 15)) | ||
>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12)) | ||
|
||
return { t, x }; | ||
>t : Symbol(t, Decl(classExpressionTest1.ts, 5, 20)) | ||
>x : Symbol(x, Decl(classExpressionTest1.ts, 5, 23)) | ||
} | ||
} | ||
|
||
var v = new C<number>(); | ||
>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7)) | ||
>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14)) | ||
|
||
return v.f<string>(); | ||
>v.f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16)) | ||
>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7)) | ||
>f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
=== tests/cases/compiler/classExpressionTest1.ts === | ||
function M() { | ||
>M : () => { t: string; x: number; } | ||
|
||
class C<X> { | ||
>C : C<X> | ||
>X : X | ||
|
||
f<T>() { | ||
>f : <T>() => { t: T; x: X; } | ||
>T : T | ||
|
||
var t: T; | ||
>t : T | ||
>T : T | ||
|
||
var x: X; | ||
>x : X | ||
>X : X | ||
|
||
return { t, x }; | ||
>{ t, x } : { t: T; x: X; } | ||
>t : T | ||
>x : X | ||
} | ||
} | ||
|
||
var v = new C<number>(); | ||
>v : C<number> | ||
>new C<number>() : C<number> | ||
>C : typeof C | ||
|
||
return v.f<string>(); | ||
>v.f<string>() : { t: string; x: number; } | ||
>v.f : <T>() => { t: T; x: number; } | ||
>v : C<number> | ||
>f : <T>() => { t: T; x: number; } | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts === | ||
function foo() { | ||
>foo : Symbol(foo, Decl(classInsideBlock.ts, 0, 0)) | ||
|
||
class C { } | ||
>C : Symbol(C, Decl(classInsideBlock.ts, 0, 16)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts === | ||
function foo() { | ||
>foo : () => void | ||
|
||
class C { } | ||
>C : C | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,18 @@ | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,5): error TS1129: Statement expected. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,6): error TS2346: Supplied parameters do not match any signature of call target. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS2304: Cannot find name 'yield'. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,22): error TS1005: ',' expected. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(9,1): error TS1128: Declaration or statement expected. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts (5 errors) ==== | ||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts (2 errors) ==== | ||
function decorator(x: any) { | ||
return y => { }; | ||
} | ||
function* g() { | ||
@decorator(yield 0) | ||
~ | ||
!!! error TS1129: Statement expected. | ||
~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2346: Supplied parameters do not match any signature of call target. | ||
~~~~~ | ||
!!! error TS2304: Cannot find name 'yield'. | ||
~ | ||
!!! error TS1005: ',' expected. | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
class C { | ||
x = yield 0; | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} | ||
} | ||
~ | ||
!!! error TS1128: Declaration or statement expected. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess classes are already block scoped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.