Closed jnm2 closed 2 years ago
How is that meant to work? There's no guarantee that the decorator returns an instance of the same type it passed in...
Oh, I see, a cast would have to be emitted after the call to this decorator and then we have a runtime failure if you return the wrong type instead of a compile-time one. That's a very good point.
Would it be possible in theory to provide an error or warning when you don't think of using generics and it is being silently ignored? I didn't think of generics right away.
@jnm2 I'm not sure how I could detect that...
I'm noticing IDE notifications that the method is unused, so I think this is actually good enough.
Edit: it's not gratuitous once you take into account that the generated code behind the scenes would otherwise have to insert a cast which could fail at runtime. Generics makes it fail at compile time which is better.
This works, but there's no real reason for the method to be generic:This does not work, and StrongInject also provides no errors or warnings: