mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
We use the same conversion codepath to handle both qualification conversions and derived-to-base conversions, because we allow both to be performed at once. However, we were previously modeling the qualification conversion as happening *first*, and producing a result whose type is the target type of the overall conversion (that is, the base class type). That led to bogus SemIR, where a `Derived` -> `const Base` conversion would first have a "compatible" conversion from `Derived` to `const Base`, *then* an access of the base subobject (of type `const Base`, within an object of type `const Base`). We now reverse the order: first we do a derived-to-base conversion, which already has logic to preserve qualifiers, and then we do any necessary qualification conversions on the result to reach the overall target type. In passing, we now skip forming the `as_compatible` instruction at all for a pure derived-to-base conversion that has no qualification conversion, simplifying the SemIR by one instruction in the common case.