We keep getting bugs like this and I keep not finding the original so I'm making a new one so we can find it.
Keywords: ignore type parameter optional inference
Problem
Often with generics, there will be some locations where a type parameter should be inferrable from usage, and other places where the type parameter should only be used to enforce typechecking. This comes up in a variety of contexts
classAnimal{move}classDogextendsAnimal{woof}functiondoSomething<T>(value: T,getDefault: ()=>T){}// Wanted an error here - getDefault() ought to return same type as 'value'doSomething(newDog(),()=>newAnimal());declarefunctionassertEqual<T>(actual: T,expected: T): boolean;constg={x: 3,y: 2};assertEqual(g,{x: 3});// Forgot y, wanted errorProposal Sketch
We should be able to mark type parameter consumption sites as being "not eligible for inference". For example, let's say we had a special global type that the compiler knew not to unwrap during inference:
Then we can annotate usage sites
functiondoSomething<T>(value: T,getDefault: ()=>NoInfer<T>){}// Wanted an error here - getDefault() ought to return same type as 'value'doSomething(newDog(),()=>newAnimal());declarefunctionassertEqual<T>(actual: T,expected: NoInfer<T>): boolean;constg={x: 3,y: 2};assertEqual(g,{x: 3});// Error
We keep getting bugs like this and I keep not finding the original so I'm making a new one so we can find it.
Keywords: ignore type parameter optional inference
Problem
Often with generics, there will be some locations where a type parameter should be inferrable from usage, and other places where the type parameter should only be used to enforce typechecking. This comes up in a variety of contexts
Proposal Sketch
We should be able to mark type parameter consumption sites as being "not eligible for inference". For example, let's say we had a special global type that the compiler knew not to unwrap during inference:
Then we can annotate usage sites