YairHalberstadt / stronginject

compile time dependency injection for .NET
MIT License
845 stars 24 forks source link

Innermost hasAwaitStarted catch block is a no-op and could be omitted #145

Open jnm2 opened 3 years ago

jnm2 commented 3 years ago

How can !hasAwaitStarted_a_1_1 in the catch block ever not evaluate to false? It's not assigned anywhere else.

https://github.com/YairHalberstadt/stronginject/blob/2143d9f27dfdf7269b4de3e60dd198c4374cd586/StrongInject.Tests.Unit/GeneratorTests.cs#L7112-L7125

YairHalberstadt commented 3 years ago

In that particular case you are right. If you want an example where this is relevant check out the testInstancePerDependencyDependenciesWithFactories. In that example async calls are parallelized - so we trigger 2 async calls then await one, then await the other. In that case you can have a situation where you need to keep track of whether an await has started.

We definitely could improve codegen to detect this scenario and remove the unnecessary bookkeeping.

jnm2 commented 3 years ago

Makes sense. I'm not too concerned. Do you want to leave this issue open to track skipping this try block for the innermost await?

YairHalberstadt commented 3 years ago

Yep, thanks