Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "incompatible dimension" errors #136

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

triallax
Copy link
Contributor

@triallax triallax commented Jul 28, 2023

Fixes #104.

TODO:

@triallax triallax changed the title Improve "incompatible dimension" errors [WIP] Improve "incompatible dimension" errors Jul 28, 2023
@triallax triallax force-pushed the improve-conversion-errors branch 3 times, most recently from 3686642 to f24c0b5 Compare August 9, 2023 20:43
@sharkdp
Copy link
Owner

sharkdp commented Aug 21, 2023

Minor: I think we should offset the physical dimension hint a bit more and maybe not use (…) parens, because this looks confusing:

  = specified dimension: Length × Mass / (Current × Time³) (ElectricFieldStrength)

Maybe:

  = specified dimension: Length × Mass / (Current × Time³)    [= ElectricFieldStrength]

@triallax triallax force-pushed the improve-conversion-errors branch 2 times, most recently from ea4b416 to a21d468 Compare August 22, 2023 20:15
numbat/src/typechecker.rs Outdated Show resolved Hide resolved
numbat/src/typechecker.rs Outdated Show resolved Hide resolved
numbat/src/typechecker.rs Outdated Show resolved Hide resolved
numbat/src/typechecker.rs Outdated Show resolved Hide resolved
numbat/src/typechecker.rs Outdated Show resolved Hide resolved
@sharkdp
Copy link
Owner

sharkdp commented Aug 23, 2023

Concerning the suggestions, I think we should only show them in a limited set of cases. For example: this suggestion is correct — but not very helpful:

>>> (20 km/h) / 2km -> hours
error: while type checking
  ┌─ <input>:1:2
  │
1 │ (20 km/h) / 2km -> hours
  │  ^^^^^^^^^^^^^^ -- ^^^^^ Time
  │  │              │   
  │  │              incompatible dimensions in unit conversion
  │  Time⁻¹
  │
  =  left hand side: Time⁻¹    [=Frequency, Activity, Rate]
    right hand side: Time  
     Suggested fix: multiply left hand side by Time²

those 1/x vs x errors are common, I believe. And typically they are not resolved by multiplying with [x]^2, but rather by inverting one side.

Another thing: it would be great to also see the [= …] abbreviated names for the suggested types:

Suggested fix: multiply left hand side by Length² × Mass / Time²    [= Torque, Energy]

numbat/src/typechecker.rs Outdated Show resolved Hide resolved
@triallax
Copy link
Contributor Author

Another thing: it would be great to also see the [= …] abbreviated names for the suggested types:

I'm not sure how to go about doing that, because the fmt method for IncompatibleDimensionsError doesn't have access to the registry to get those dimension names. Any suggestions?

@sharkdp
Copy link
Owner

sharkdp commented Aug 24, 2023

Another thing: it would be great to also see the [= …] abbreviated names for the suggested types:

I'm not sure how to go about doing that, because the fmt method for IncompatibleDimensionsError doesn't have access to the registry to get those dimension names. Any suggestions?

let's skip it for now

@triallax triallax changed the title [WIP] Improve "incompatible dimension" errors Improve "incompatible dimension" errors Aug 28, 2023
@triallax
Copy link
Contributor Author

@sharkdp please squash when you merge, I don't want my horrible commit messages forever in the commit log (also, please remove the commit titles from the squashed commit's description).

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much. Great work 👍

This changeset enhances "incompatible dimensions" errors by aligning
them for better readability, adding additional information and providing
suggestions on how to fix them.

closes #104
@sharkdp sharkdp merged commit 1ce9496 into master Aug 29, 2023
1 check passed
@sharkdp sharkdp deleted the improve-conversion-errors branch August 29, 2023 08:10
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.

Better incompatible-dimension / conversion errors
2 participants