mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Generic functions are never context sensitive (#37811)
* Functions with type parameters are never contextsensitive * Add tests
This commit is contained in:
parent
eac073894b
commit
5a4024dd9d
@ -14251,7 +14251,7 @@ namespace ts {
|
||||
|
||||
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
|
||||
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
|
||||
return !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
|
||||
return !node.typeParameters && !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
|
||||
}
|
||||
|
||||
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
//// [genericFunctionsNotContextSensitive.ts]
|
||||
// Repro from #37110
|
||||
|
||||
const f = <F extends (...args: any[]) => <G>(x: G) => void>(_: F): F => _;
|
||||
|
||||
const a = f(<K extends string>(_: K) => _ => ({})); // <K extends string>(_: K) => <G>(_: G) => {}
|
||||
|
||||
|
||||
//// [genericFunctionsNotContextSensitive.js]
|
||||
"use strict";
|
||||
// Repro from #37110
|
||||
var f = function (_) { return _; };
|
||||
var a = f(function (_) { return function (_) { return ({}); }; }); // <K extends string>(_: K) => <G>(_: G) => {}
|
||||
@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/genericFunctionsNotContextSensitive.ts ===
|
||||
// Repro from #37110
|
||||
|
||||
const f = <F extends (...args: any[]) => <G>(x: G) => void>(_: F): F => _;
|
||||
>f : Symbol(f, Decl(genericFunctionsNotContextSensitive.ts, 2, 5))
|
||||
>F : Symbol(F, Decl(genericFunctionsNotContextSensitive.ts, 2, 11))
|
||||
>args : Symbol(args, Decl(genericFunctionsNotContextSensitive.ts, 2, 22))
|
||||
>G : Symbol(G, Decl(genericFunctionsNotContextSensitive.ts, 2, 42))
|
||||
>x : Symbol(x, Decl(genericFunctionsNotContextSensitive.ts, 2, 45))
|
||||
>G : Symbol(G, Decl(genericFunctionsNotContextSensitive.ts, 2, 42))
|
||||
>_ : Symbol(_, Decl(genericFunctionsNotContextSensitive.ts, 2, 60))
|
||||
>F : Symbol(F, Decl(genericFunctionsNotContextSensitive.ts, 2, 11))
|
||||
>F : Symbol(F, Decl(genericFunctionsNotContextSensitive.ts, 2, 11))
|
||||
>_ : Symbol(_, Decl(genericFunctionsNotContextSensitive.ts, 2, 60))
|
||||
|
||||
const a = f(<K extends string>(_: K) => _ => ({})); // <K extends string>(_: K) => <G>(_: G) => {}
|
||||
>a : Symbol(a, Decl(genericFunctionsNotContextSensitive.ts, 4, 5))
|
||||
>f : Symbol(f, Decl(genericFunctionsNotContextSensitive.ts, 2, 5))
|
||||
>K : Symbol(K, Decl(genericFunctionsNotContextSensitive.ts, 4, 13))
|
||||
>_ : Symbol(_, Decl(genericFunctionsNotContextSensitive.ts, 4, 31))
|
||||
>K : Symbol(K, Decl(genericFunctionsNotContextSensitive.ts, 4, 13))
|
||||
>_ : Symbol(_, Decl(genericFunctionsNotContextSensitive.ts, 4, 39))
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/genericFunctionsNotContextSensitive.ts ===
|
||||
// Repro from #37110
|
||||
|
||||
const f = <F extends (...args: any[]) => <G>(x: G) => void>(_: F): F => _;
|
||||
>f : <F extends (...args: any[]) => <G>(x: G) => void>(_: F) => F
|
||||
><F extends (...args: any[]) => <G>(x: G) => void>(_: F): F => _ : <F extends (...args: any[]) => <G>(x: G) => void>(_: F) => F
|
||||
>args : any[]
|
||||
>x : G
|
||||
>_ : F
|
||||
>_ : F
|
||||
|
||||
const a = f(<K extends string>(_: K) => _ => ({})); // <K extends string>(_: K) => <G>(_: G) => {}
|
||||
>a : <K extends string>(_: K) => <G>(_: G) => {}
|
||||
>f(<K extends string>(_: K) => _ => ({})) : <K extends string>(_: K) => <G>(_: G) => {}
|
||||
>f : <F extends (...args: any[]) => <G>(x: G) => void>(_: F) => F
|
||||
><K extends string>(_: K) => _ => ({}) : <K extends string>(_: K) => <G>(_: G) => {}
|
||||
>_ : K
|
||||
>_ => ({}) : <G>(_: G) => {}
|
||||
>_ : G
|
||||
>({}) : {}
|
||||
>{} : {}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
// @strict: true
|
||||
|
||||
// Repro from #37110
|
||||
|
||||
const f = <F extends (...args: any[]) => <G>(x: G) => void>(_: F): F => _;
|
||||
|
||||
const a = f(<K extends string>(_: K) => _ => ({})); // <K extends string>(_: K) => <G>(_: G) => {}
|
||||
Loading…
x
Reference in New Issue
Block a user