microsoft / microsoft/TypeScript
Instantiations of constrained generic signatures allow all assignments
@weswigham y travaille déjà.
Depuis le 7/9/2023.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
🔎 Search Terms
variance generic signature measurement
🕗 Version & Regression Information
This has been our behavior forever as far as I can tell - in fact, I've seen this pattern used once or twice to work around other bugs, even though the behavior is in no way safe.
⏯ Playground Link
💻 Code
type Fn<T> = <U extends T>(x: U) => U;
type Concrete1 = <U extends number>(x: U) => U;
type Concrete2 = <U extends string>(x: U) => U;
function f<T1, T2>(t1: Fn<T1>, t2: Fn<T2>, c1: Concrete1, c2: Concrete2) {
// every single one of these assignments should error
t1 = t2; // should error, but doesn't
t2 = t1; // should error, but doesn't
c1 = c2;
c2 = c1;
t1 = c1;
c1 = t1;
}
🙁 Actual behavior
Missing two errors on the generic relationships.
🙂 Expected behavior
All of the assignments are errors, as the generic relationship should be even stricter than the non-generic one.
Additional information about the issue
The issue lies in our variance analysis - we currently incorrectly measure T as independent, which is quite different from the invariant it should adopt (via U's invariant usages). This discrepancy arises because of some oddities in how we do generic signature relationships.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.