Skip to content

Conversation

@abs0luty
Copy link
Contributor

@abs0luty abs0luty force-pushed the descriptive-type-mismatch branch 2 times, most recently from d3d31b2 to 6167eb0 Compare October 20, 2025 21:33
@abs0luty abs0luty force-pushed the descriptive-type-mismatch branch from 6167eb0 to 4b683c2 Compare October 20, 2025 21:35
// If we get here, we have exactly 1 mismatch at depth 1
// This is like List(Int) vs List(String) - simple enough to not need smart diff
false
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpil what's your opinion on when to display errors this way?

@giacomocavalieri
Copy link
Member

I would also like to think how these will appear in different settings. As nice as this looks when running gleam build I think it could get confusing real fast when the error pops up in an IDE like Zed or VSCode where wrapping can happen:

  • VSCode: Screenshot 2025-10-21 alle 11 36 41
  • Zed: Screenshot 2025-10-21 alle 11 36 54

@lpil
Copy link
Member

lpil commented Oct 21, 2025

That looks like a bug in Zed to me @giacomocavalieri. We tell it to render it as markdown.

@giacomocavalieri
Copy link
Member

Yeah, the wrapping can still make it hard to read though

@abs0luty
Copy link
Contributor Author

abs0luty commented Oct 21, 2025

@giacomocavalieri Good point about wrapping. Thanks! I think we can solve it in many different ways:

We can break the mismatch into bullet points under the main message. Something like "Mismatch at argument 2: expected Float, found String" without trying to align under the original text, or something like this:

Box(#(#(Int, a), b, List(c)))

Expected a to be Float, found String
Expected b to be Float, found Int
Expected c to be Float, found Int

Or even separate error messages:

Box(#(#(Int, ...), Int, List(Int)))
  
Expected type: Float
Found type: String

Box(#(#(Int, String), ..., List(Int)))
  
Expected type: Float
Found type: Int

Box(#(#(Int, String), Int, List(...)))
  
Expected type: Float
Found type: Int

We can also control the block width manually (e.g., add zero-width spaces or break into smaller lines ourselves), although there's always a limit to this:

Box(
  #(
    #(Int, String),
           ^^^^^^ expected Float
    Int,
    ^^^ expected Float
    List(Int)
         ^^^ expected Float
  )
)

What do you think?

@abs0luty abs0luty marked this pull request as draft October 21, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emphasize mismatching part of complex type mismatches

3 participants