Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Constraint check compares a type parameter's TypeVar, not its instantiation: nested generic calls warn on code tsc accepts

Aperta
#12,978 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Ambito
backend, compilers

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 to return_type: Unknown. So Perry compares against the correct bound and still rejects TypeVar("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/perry 0.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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PerryTS/perry

Tutte le issue di PerryTS/perry

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.