mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
44 lines
1.8 KiB
Plaintext
44 lines
1.8 KiB
Plaintext
//// [tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts] ////
|
|
|
|
=== constructorParameterShadowsOuterScopes.ts ===
|
|
// Initializer expressions for instance member variables are evaluated in the scope of the class constructor
|
|
// body but are not permitted to reference parameters or local variables of the constructor.
|
|
// This effectively means that entities from outer scopes by the same name as a constructor parameter or
|
|
// local variable are inaccessible in initializer expressions for instance member variables
|
|
|
|
var x = 1;
|
|
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 5, 3))
|
|
|
|
class C {
|
|
>C : Symbol(C, Decl(constructorParameterShadowsOuterScopes.ts, 5, 10))
|
|
|
|
b = x; // error, evaluated in scope of constructor, cannot reference x
|
|
>b : Symbol(C.b, Decl(constructorParameterShadowsOuterScopes.ts, 6, 9))
|
|
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 5, 3))
|
|
|
|
constructor(x: string) {
|
|
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
|
|
|
|
x = 2; // error, x is string
|
|
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
|
|
}
|
|
}
|
|
|
|
var y = 1;
|
|
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 13, 3))
|
|
|
|
class D {
|
|
>D : Symbol(D, Decl(constructorParameterShadowsOuterScopes.ts, 13, 10))
|
|
|
|
b = y; // error, evaluated in scope of constructor, cannot reference y
|
|
>b : Symbol(D.b, Decl(constructorParameterShadowsOuterScopes.ts, 14, 9))
|
|
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 13, 3))
|
|
|
|
constructor(x: string) {
|
|
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 16, 16))
|
|
|
|
var y = "";
|
|
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 17, 11))
|
|
}
|
|
}
|