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
The issue here is that type parameters introduced by a class declaration should not be in scope within the expression part of the base class heritage clause. However, when a type argument list follows the expression part, they should be in scope there. So, this should be an error
classGen<T>extendsbase<T>(){}// Error, T not in scope in base class expression
Mark Boyall (@markboyall) Yes, you'd need to wrap the derived class in a function as well such that you can pass a type parameter that differs per invocation. For example:
The lifetime of the statics above is one per invocation of their containing function. Effectively, a class declaration manufactures a class constructor function each time it is executed (which is only once for a global class, but can be many times for a class nested in a function).
Activity
[-]Extend Generic static bug[/-][+]Extend generic static bug[/+]ahejlsberg commentedon Aug 16, 2017
The issue here is that type parameters introduced by a class declaration should not be in scope within the expression part of the base class heritage clause. However, when a type argument list follows the expression part, they should be in scope there. So, this should be an error
markboyall commentedon Aug 17, 2017
Then... how would you implement the Gen class above? Or would it need to be wrapped as well?
I'm not even sure what the lifetime of the static inside the base class is, whether it's one per call of base, or just one.
ahejlsberg commentedon Aug 17, 2017
Mark Boyall (@markboyall) Yes, you'd need to wrap the derived class in a function as well such that you can pass a type parameter that differs per invocation. For example:
The lifetime of the statics above is one per invocation of their containing function. Effectively, a class declaration manufactures a class constructor function each time it is executed (which is only once for a global class, but can be many times for a class nested in a function).