You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, fixingTypeParametersRepeatedly3.ts, added in #2356, but it was accepted in #16368 (strict generic checks) with a (tiny, unnoticeable in all the other changes) baseline showing the fault.
Code
interfaceBase{baseProp;}interfaceDerivedextendsBase{toBase?(): Base;}varderived: Derived;declarefunctionfoo<T>(x: T,func: (p: T)=>T): T;varresult=foo(derived,d=>d.toBase());// bar should type check just like foo.// result2 should have the same type as resultdeclarefunctionbar<T>(x: T,func: (p: T)=>T): T;declarefunctionbar<T>(x: T,func: (p: T)=>T): T;varresult2=bar(derived,d=>d.toBase());
Expected behavior: result and result2 are assigned the same type (there's a comment in the test asserting as much) - they are implemented identically except bar has an extra identical overload. (note: this can happen easily in the real world nowadays via intersection types! Intersecting multiple interfaces with similar base interfaces can cause exactly this situation.)
Actual behavior: result typechecks as Derived result2 typechecks as Base (seems wrong, since Base definitely doesn't have the toBase method used in the callback!)
Derived and Base are assignable to one another here, since toBase is optional, which is why the inference can succeed at all; however, Base, as reported in the second case can't actually have been the type used to typecheck the lambda body, as the toBase call doesn't cause an error in the test - I think the likely reason for the change in behavior is this removal, based on the content of the removed comment.
The text was updated successfully, but these errors were encountered:
Note: you can make the behavior between the two identical by removing the optimization within resolveCall that skips the subtype check on single-signature calls that's done prior to the assignability check. Unfortunately, they become identical in the bad behavior (both become a non-erroring Base) - that explains the difference; it's definitely because the first chooseOverload call with subtype relationship is failing (as expected) but still incorrectly permanently setting parameter types on the signature associated with the untyped lambda.
I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this,
fixingTypeParametersRepeatedly3.ts
, added in #2356, but it was accepted in #16368 (strict generic checks) with a (tiny, unnoticeable in all the other changes) baseline showing the fault.Code
Expected behavior:
result
andresult2
are assigned the same type (there's a comment in the test asserting as much) - they are implemented identically exceptbar
has an extra identical overload. (note: this can happen easily in the real world nowadays via intersection types! Intersecting multiple interfaces with similar base interfaces can cause exactly this situation.)Actual behavior:
result
typechecks asDerived
result2
typechecks asBase
(seems wrong, sinceBase
definitely doesn't have thetoBase
method used in the callback!)Derived
andBase
are assignable to one another here, sincetoBase
is optional, which is why the inference can succeed at all; however,Base
, as reported in the second case can't actually have been the type used to typecheck the lambda body, as thetoBase
call doesn't cause an error in the test - I think the likely reason for the change in behavior is this removal, based on the content of the removed comment.The text was updated successfully, but these errors were encountered: