Fix CS0266 in GetUnitInfo<TQuantity,TUnit> typed overload#1677
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1677 +/- ##
======================================
Coverage 96% 96%
======================================
Files 450 450
Lines 29177 29178 +1
======================================
+ Hits 28136 28137 +1
Misses 1041 1041 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The Azure Pipelines build of #1657 (master) fails with: error CS0266: Cannot implicitly convert type 'UnitInfo<TUnit>' to 'UnitInfo<TQuantity, TUnit>' at: return quantity.QuantityInfo[quantity.Unit]; The receiver is statically IQuantity<TQuantity, TUnit>, whose QuantityInfo getter is shadowed (`new`) to return the more specific QuantityInfo<TQuantity, TUnit>. Roslyn's member lookup on hosted images resolves the inherited IQuantity<TUnit>.QuantityInfo (QuantityInfo<TUnit>) instead, so the indexer returns UnitInfo<TUnit> and the conversion to UnitInfo<TQuantity, TUnit> fails. The runtime value is always the more derived type, so cast through QuantityInfo<TQuantity, TUnit> explicitly to surface the typed indexer. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cc579d7 to
a959971
Compare
PR Review: Fix CS0266 in
|
Summary
Fixes the Azure Pipelines build failure introduced by #1657:
```
error CS0266: Cannot implicitly convert type 'UnitsNet.UnitInfo' to
'UnitsNet.UnitInfo<TQuantity, TUnit>'
```
at UnitsNet/Extensions/QuantityExtensions.cs:47:
```csharp
return quantity.QuantityInfo[quantity.Unit];
```
Why this happens
The receiver is statically
IQuantity<TQuantity, TUnit>, whoseQuantityInfogetter is shadowed (new) to return the more specificQuantityInfo<TQuantity, TUnit>. On the hosted Azure Pipelines image's Roslyn build, member lookup resolves to the inheritedIQuantity<TUnit>.QuantityInfo(QuantityInfo<TUnit>) instead, so the indexer returnsUnitInfo<TUnit>and the conversion toUnitInfo<TQuantity, TUnit>fails. Local builds on newer SDKs happened to resolve the shadowed member and compiled cleanly, which is why #1657's CI never tripped on the maintainer's machine.Fix
The runtime value is always the more derived type, so cast through
QuantityInfo<TQuantity, TUnit>explicitly to surface the typed indexer. No behavior change.🤖 Generated with Claude Code