Constraint check compares a type parameter's TypeVar, not its instantiation: nested generic calls warn on code tsc accepts
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust, typescript
Direzione di ricerca
Start by tracing generic call argument type checking in the Rust compiler, using the reported TypeVar("F") versus instantiated argument type as the clue. Compare the nested generic call with the direct inQueryConnection(calculate) case, then run or add a regression case based on the reproducer. Done means the nested call compiles without the constraint warning while preserving correct behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
perry compile warns on code tsc --strict accepts, whenever the argument to a generic function is itself the result of a generic call. The compiler appears to check the uninstantiated type variable against the parameter's constraint instead of the type it was instantiated to, and no type variable can satisfy a function-shape constraint.
Benign: it is a warning, codegen continues, and the binary runs correctly. This is a diagnostic-quality bug, not a blocker — but it fires on ordinary decorator-style composition, so it is noisy on real code.
Reproducer
interface Rel { n: number }
function inQueryConnection<F extends (this: Rel, ...args: never[]) => Promise<any>>(fn: F): F {
return function (this: Rel, ...args: unknown[]) {
return fn.apply(this, args as never[]);
} as unknown as F;
}
function withDeferred<F extends (this: Rel, ...args: never[]) => unknown>(fn: F): F {
return function (this: Rel, ...args: never[]) {
return fn.apply(this, args);
} as unknown as F;
}
async function calculate(this: Rel, op?: string): Promise<number> {
return op ? 1 : this.n;
}
export const Calculations = {
calculate: inQueryConnection(withDeferred(calculate)),
};
console.log(`[repro] ${await Calculations.calculate.call({ n: 7 })}`);
Observed
Warning: Constraint violation in function 'inQueryConnection': TypeMismatch {
type_param: "F",
expected: Function(FunctionType { params: [("this", Named("Rel"), false),
("_rest", Array(Never), false)], return_type: Promise(Any),
is_async: false, is_generator: false }),
actual: TypeVar("F") }
The binary then compiles, links and prints [repro] 7, which is correct.
Expected
No warning. withDeferred(calculate) has type typeof calculate, which satisfies inQueryConnection's constraint. tsc --ignoreConfig --strict --target es2022 --module esnext --moduleResolution bundler --noEmit exits 0 on the same file (TypeScript 7.1.0-dev.20260920.1).
What narrows it
- It is not a bound mismatch. Widening the outer bound from
=> Promise<any>to=> unknown, so both bounds are identical, still warns — the message only changes toreturn_type: Unknown. So Perry compares against the correct bound and still rejectsTypeVar("F"). actual: TypeVar("F")is the tell: the argument is reported as the type variable, not as the type it was instantiated to.- Calling
inQueryConnection(calculate)directly — a non-generic argument — does not warn. The nesting is required.
Environment
- Perry
main@20fde48d, built from source, Linux x86_64, LLVM 22.1.8, rustc 1.101.0-nightly - Also reproduces on npm
@perryts/perry0.5.1520 and on from-source 0.5.1662
Found while compiling a TypeScript web framework ahead-of-time; the original site is a query-method wrapper composed exactly this way.
- Lingua principale
- Rust
- Stelle
- 4.9k
- Fork
- 166
- Merge medio
- 1h 48m
- PR unite (30g)
- 914
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PerryTS/perry
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
perf(regex): capture-heavy exec is 15.9x Node — GC accounting is as large a share as the matcherAperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 48/100
PerryTS/perry#13139 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 73/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PerryTS/perry
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
farion1231/cc-switch#8829 ·
I maintainer di solito rispondono entro 1 giorno
-
Validate CI command vectors before indexing Cargo subcommandsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug ci good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
longbridge/gpui-kit#3677 ·
I maintainer di solito rispondono entro 1 giorno
-
E-pr-welcome
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
seanmonstar/reqwest#3121 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
ilya-zlobintsev/LACT#1235 ·
I maintainer di solito rispondono entro 1 giorno