stronginject icon indicating copy to clipboard operation
stronginject copied to clipboard

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

Open jnm2 opened this issue 2 years ago • 3 comments

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

jnm2 avatar Aug 15 '21 01:08 jnm2

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.

YairHalberstadt avatar Aug 15 '21 04:08 YairHalberstadt

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?

jnm2 avatar Aug 15 '21 14:08 jnm2

Yep, thanks

YairHalberstadt avatar Aug 15 '21 14:08 YairHalberstadt