Skip to content

Print reasons for subtyping mismatches #167

@kaleidawave

Description

@kaleidawave

When doing subtyping (initial declaration, assigning, passing argument as parameter, return type etc) the returned result is a SubTypeResult. The subtyping logic (in types/subtyping.rs) currently collects some of the reasons for mismatches when doing the checking and stores this as a NonEqualityReason.

However this reason is thrown away in many places and does not make it to diagnostics. This can be shown by running rg "SubTypeResult::IsNotSubType\(_".

It would be better to pass this via a field to many of the diagnostics. For example here

DoesNotMeetConstraint {
variable_type: TypeStringRepresentation,
variable_site: SpanWithSource,
value_type: TypeStringRepresentation,
value_site: SpanWithSource,
},

There should be something like mismatch: MismatchExplanation. This can be turned into a user readable explanation of why the type error happened. This can be surfaced via adding labels in the Diagnostic::PositionWithAdditionalLabels.

The TypeStringRepresentation enum was designed to cover this, but I don't think it quite fits into this structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions