Skip to content

Avoid bogus circularity error on context sensitive expando assingment #50487

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 2 commits into from
Mar 16, 2023
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: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28942,7 +28942,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return undefined;
}
}
return isInJSFile(decl) ? undefined : getTypeOfExpression(binaryExpression.left);
return isInJSFile(decl) || decl === binaryExpression.left ? undefined : getTypeOfExpression(binaryExpression.left);
}
case AssignmentDeclarationKind.ExportsProperty:
case AssignmentDeclarationKind.Prototype:
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [contextualReturnTypeOfIIFE2.ts]
declare namespace app {
function foo(): void;
}

app.foo.bar = (function () {
const someFun = (arg: number) => {};
return { someFun };
})();

app.foo.bar.someFun(1);


//// [contextualReturnTypeOfIIFE2.js]
app.foo.bar = (function () {
var someFun = function (arg) { };
return { someFun: someFun };
})();
app.foo.bar.someFun(1);
33 changes: 33 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
declare namespace app {
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))

function foo(): void;
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
}

app.foo.bar = (function () {
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))

const someFun = (arg: number) => {};
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 5, 7))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE2.ts, 5, 19))

return { someFun };
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))

})();

app.foo.bar.someFun(1);
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))

41 changes: 41 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
declare namespace app {
>app : typeof app

function foo(): void;
>foo : typeof foo
}

app.foo.bar = (function () {
>app.foo.bar = (function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : typeof app.foo
>app : typeof app
>foo : typeof app.foo
>bar : { someFun: (arg: number) => void; }
>(function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
>(function () { const someFun = (arg: number) => {}; return { someFun };}) : () => { someFun: (arg: number) => void; }
>function () { const someFun = (arg: number) => {}; return { someFun };} : () => { someFun: (arg: number) => void; }

const someFun = (arg: number) => {};
>someFun : (arg: number) => void
>(arg: number) => {} : (arg: number) => void
>arg : number

return { someFun };
>{ someFun } : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void

})();

app.foo.bar.someFun(1);
>app.foo.bar.someFun(1) : void
>app.foo.bar.someFun : (arg: number) => void
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : typeof app.foo
>app : typeof app
>foo : typeof app.foo
>bar : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void
>1 : 1

21 changes: 21 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [contextualReturnTypeOfIIFE3.ts]
declare namespace app {
var foo: {
bar: {
someFun: (arg: number) => void;
};
};
}

app.foo.bar = (function () {
return { someFun(arg) {} };
})();

app.foo.bar.someFun(1);


//// [contextualReturnTypeOfIIFE3.js]
app.foo.bar = (function () {
return { someFun: function (arg) { } };
})();
app.foo.bar.someFun(1);
40 changes: 40 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE3.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
declare namespace app {
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))

var foo: {
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))

bar: {
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))

someFun: (arg: number) => void;
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 3, 16))

};
};
}

app.foo.bar = (function () {
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))

return { someFun(arg) {} };
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 9, 10))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 9, 19))

})();

app.foo.bar.someFun(1);
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))

47 changes: 47 additions & 0 deletions tests/baselines/reference/contextualReturnTypeOfIIFE3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
declare namespace app {
>app : typeof app

var foo: {
>foo : { bar: { someFun: (arg: number) => void; }; }

bar: {
>bar : { someFun: (arg: number) => void; }

someFun: (arg: number) => void;
>someFun : (arg: number) => void
>arg : number

};
};
}

app.foo.bar = (function () {
>app.foo.bar = (function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : { bar: { someFun: (arg: number) => void; }; }
>app : typeof app
>foo : { bar: { someFun: (arg: number) => void; }; }
>bar : { someFun: (arg: number) => void; }
>(function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
>(function () { return { someFun(arg) {} };}) : () => { someFun(arg: number): void; }
>function () { return { someFun(arg) {} };} : () => { someFun(arg: number): void; }

return { someFun(arg) {} };
>{ someFun(arg) {} } : { someFun(arg: number): void; }
>someFun : (arg: number) => void
>arg : number

})();

app.foo.bar.someFun(1);
>app.foo.bar.someFun(1) : void
>app.foo.bar.someFun : (arg: number) => void
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : { bar: { someFun: (arg: number) => void; }; }
>app : typeof app
>foo : { bar: { someFun: (arg: number) => void; }; }
>bar : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void
>1 : 1

13 changes: 13 additions & 0 deletions tests/cases/compiler/contextualReturnTypeOfIIFE2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @lib: esnext
// @noImplicitAny: true

declare namespace app {
function foo(): void;
}

app.foo.bar = (function () {
const someFun = (arg: number) => {};
return { someFun };
})();

app.foo.bar.someFun(1);
16 changes: 16 additions & 0 deletions tests/cases/compiler/contextualReturnTypeOfIIFE3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @lib: esnext
// @noImplicitAny: true

declare namespace app {
var foo: {
bar: {
someFun: (arg: number) => void;
};
};
}

app.foo.bar = (function () {
return { someFun(arg) {} };
})();

app.foo.bar.someFun(1);