Merge pull request #26483 from Microsoft/fix20594

Ensure for-in loop variable is checked
This commit is contained in:
Ron Buckton 2018-08-22 11:41:17 -07:00 committed by GitHub
commit 1f8aa057f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 2 deletions

View file

@ -18382,7 +18382,7 @@ namespace ts {
return errorType;
}
const indexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : checkExpression(indexExpression);
const indexType = checkExpression(indexExpression);
if (objectType === errorType || objectType === silentNeverType) {
return objectType;
@ -18393,7 +18393,7 @@ namespace ts {
return errorType;
}
return checkIndexedAccessIndexType(getIndexedAccessType(objectType, indexType, node), node);
return checkIndexedAccessIndexType(getIndexedAccessType(objectType, isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType, node), node);
}
function checkThatExpressionIsProperSymbolReference(expression: Expression, expressionType: Type, reportError: boolean): boolean {

View file

@ -111,6 +111,16 @@ for (const y = 0; y < 1;) {
const x = 1;
(function() { return x + y});
(() => x + y);
}
// https://github.com/Microsoft/TypeScript/issues/20594
declare const sobj: { [x: string]: any };
for (let sx in sobj) {
(() => sobj[sx]);
}
declare const iobj: { [x: number]: any };
for (let ix in iobj) {
(() => iobj[ix]);
}
//// [capturedLetConstInLoop1.js]
@ -270,3 +280,15 @@ var _loop_20 = function (y) {
for (var y = 0; y < 1;) {
_loop_20(y);
}
var _loop_21 = function (sx) {
(function () { return sobj[sx]; });
};
for (var sx in sobj) {
_loop_21(sx);
}
var _loop_22 = function (ix) {
(function () { return iobj[ix]; });
};
for (var ix in iobj) {
_loop_22(ix);
}

View file

@ -258,3 +258,29 @@ for (const y = 0; y < 1;) {
>x : Symbol(x, Decl(capturedLetConstInLoop1.ts, 109, 9))
>y : Symbol(y, Decl(capturedLetConstInLoop1.ts, 108, 10))
}
// https://github.com/Microsoft/TypeScript/issues/20594
declare const sobj: { [x: string]: any };
>sobj : Symbol(sobj, Decl(capturedLetConstInLoop1.ts, 115, 13))
>x : Symbol(x, Decl(capturedLetConstInLoop1.ts, 115, 23))
for (let sx in sobj) {
>sx : Symbol(sx, Decl(capturedLetConstInLoop1.ts, 116, 8))
>sobj : Symbol(sobj, Decl(capturedLetConstInLoop1.ts, 115, 13))
(() => sobj[sx]);
>sobj : Symbol(sobj, Decl(capturedLetConstInLoop1.ts, 115, 13))
>sx : Symbol(sx, Decl(capturedLetConstInLoop1.ts, 116, 8))
}
declare const iobj: { [x: number]: any };
>iobj : Symbol(iobj, Decl(capturedLetConstInLoop1.ts, 119, 13))
>x : Symbol(x, Decl(capturedLetConstInLoop1.ts, 119, 23))
for (let ix in iobj) {
>ix : Symbol(ix, Decl(capturedLetConstInLoop1.ts, 120, 8))
>iobj : Symbol(iobj, Decl(capturedLetConstInLoop1.ts, 119, 13))
(() => iobj[ix]);
>iobj : Symbol(iobj, Decl(capturedLetConstInLoop1.ts, 119, 13))
>ix : Symbol(ix, Decl(capturedLetConstInLoop1.ts, 120, 8))
}

View file

@ -426,3 +426,35 @@ for (const y = 0; y < 1;) {
>x : 1
>y : 0
}
// https://github.com/Microsoft/TypeScript/issues/20594
declare const sobj: { [x: string]: any };
>sobj : { [x: string]: any; }
>x : string
for (let sx in sobj) {
>sx : string
>sobj : { [x: string]: any; }
(() => sobj[sx]);
>(() => sobj[sx]) : () => any
>() => sobj[sx] : () => any
>sobj[sx] : any
>sobj : { [x: string]: any; }
>sx : string
}
declare const iobj: { [x: number]: any };
>iobj : { [x: number]: any; }
>x : number
for (let ix in iobj) {
>ix : string
>iobj : { [x: number]: any; }
(() => iobj[ix]);
>(() => iobj[ix]) : () => any
>() => iobj[ix] : () => any
>iobj[ix] : any
>iobj : { [x: number]: any; }
>ix : string
}

View file

@ -110,4 +110,14 @@ for (const y = 0; y < 1;) {
const x = 1;
(function() { return x + y});
(() => x + y);
}
// https://github.com/Microsoft/TypeScript/issues/20594
declare const sobj: { [x: string]: any };
for (let sx in sobj) {
(() => sobj[sx]);
}
declare const iobj: { [x: number]: any };
for (let ix in iobj) {
(() => iobj[ix]);
}