mirtypes: properly translate recursive imported types #1642
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix an internal issue with MIR type translation of recursive
imported types.
Details
In the MIR type IR, imported types use a dedicated type kind
(
tkImported
), which has the "to be treated as" type as the element/base.
Due to unconditionally updating the
PType
->MIR mapping whentranslating
importc
ed object types, usages of the imported typeswithin their own body (via a pointer/ref indirection) used the
tkStruct
symbol, not thetkImported
symbol.This led to internal type mismatches between the actual and computed
type of MIR access expression, but since the type of access expressions
is never recomputed at the moment, the bug had no user-facing effect.
To fix the bug,
handleImported
now adds a symbol and registers amapping right away, with creation of a MIR type symbol for the
"internal" type of
importc
ed types leaving the mapping as is.