Skip to content

Commit

Permalink
Check for undefined source.symbol (#37021)
Browse files Browse the repository at this point in the history
Fixes #37014
  • Loading branch information
RyanCavanaugh authored Feb 25, 2020
1 parent 3e4ce47 commit 43863ca
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16273,6 +16273,7 @@ namespace ts {
if (unmatchedProperty.valueDeclaration
&& isNamedDeclaration(unmatchedProperty.valueDeclaration)
&& isPrivateIdentifier(unmatchedProperty.valueDeclaration.name)
&& source.symbol
&& source.symbol.flags & SymbolFlags.Class) {
const privateIdentifierDescription = unmatchedProperty.valueDeclaration.name.escapedText;
const symbolTableKey = getSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts(2,3): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts(5,7): error TS2741: Property '#field' is missing in type '{}' but required in type 'Class'.


==== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts (2 errors) ====
export class Class {
#field: any
~~~~~~
!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
}

const task: Class = {} as unknown;
~~~~
!!! error TS2741: Property '#field' is missing in type '{}' but required in type 'Class'.
!!! related TS2728 tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts:2:3: '#field' is declared here.

21 changes: 21 additions & 0 deletions tests/baselines/reference/privateFieldAssignabilityFromUnknown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [privateFieldAssignabilityFromUnknown.ts]
export class Class {
#field: any
}

const task: Class = {} as unknown;


//// [privateFieldAssignabilityFromUnknown.js]
"use strict";
var _field;
exports.__esModule = true;
var Class = /** @class */ (function () {
function Class() {
_field.set(this, void 0);
}
return Class;
}());
exports.Class = Class;
_field = new WeakMap();
var task = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts ===
export class Class {
>Class : Symbol(Class, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 0))

#field: any
>#field : Symbol(Class.#field, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 20))
}

const task: Class = {} as unknown;
>task : Symbol(task, Decl(privateFieldAssignabilityFromUnknown.ts, 4, 5))
>Class : Symbol(Class, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 0))

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts ===
export class Class {
>Class : Class

#field: any
>#field : any
}

const task: Class = {} as unknown;
>task : Class
>{} as unknown : unknown
>{} : {}

5 changes: 5 additions & 0 deletions tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class Class {
#field: any
}

const task: Class = {} as unknown;

0 comments on commit 43863ca

Please sign in to comment.