Skip to content

Set parent pointers on manufactured reference for property initialization check (#27246) #27252

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

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26176,6 +26176,8 @@ namespace ts {

function isPropertyInitializedInConstructor(propName: Identifier, propType: Type, constructor: ConstructorDeclaration) {
const reference = createPropertyAccess(createThis(), propName);
reference.expression.parent = reference;
reference.parent = constructor;
reference.flowNode = constructor.returnFlowNode;
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/strictBooleanMemberAssignability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [strictBooleanMemberAssignability.ts]
class Abc {
def: boolean
constructor() {
this.def = true
}
}

//// [strictBooleanMemberAssignability.js]
"use strict";
var Abc = /** @class */ (function () {
function Abc() {
this.def = true;
}
return Abc;
}());
14 changes: 14 additions & 0 deletions tests/baselines/reference/strictBooleanMemberAssignability.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
class Abc {
>Abc : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))

def: boolean
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))

constructor() {
this.def = true
>this.def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
>this : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
}
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/strictBooleanMemberAssignability.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
class Abc {
>Abc : Abc

def: boolean
>def : boolean

constructor() {
this.def = true
>this.def = true : true
>this.def : boolean
>this : this
>def : boolean
>true : true
}
}
7 changes: 7 additions & 0 deletions tests/cases/compiler/strictBooleanMemberAssignability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @strict: true
class Abc {
def: boolean
constructor() {
this.def = true
}
}