Skip to content

Do not show coercion suggestion when coercion isn't possible #7721

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

Merged
merged 2 commits into from
Jul 25, 2025

Conversation

zth
Copy link
Collaborator

@zth zth commented Jul 25, 2025

Prior to this PR, this code:

let x: dict<JSON.t> = dict{"1": 1.}

...would give this error:

This has type: dict<float>
  But it's expected to have type: dict<JSON.t>
  
  The incompatible parts:
    float vs JSON.t (defined as JSON.t)
  
  Possible solutions: 
  - These types are compatible at runtime. You can use the coercion operator to convert to the expected type: (dict{"a": 1.} :> JSON.t)

Notice how it's suggesting a coercion that won't compile. That's because I was checking if the inner most types were coercable, but we must check the outer most types since it's the full type + expression that would need to be coerced.

This PR fixes that oversight.

@zth zth requested review from cknitt and cristianoc July 25, 2025 18:15
Copy link

pkg-pr-new bot commented Jul 25, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7721

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7721

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7721

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7721

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7721

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7721

commit: 11fdc2f

@zth zth force-pushed the fix-coercion-message-bug branch from 94f3243 to 11fdc2f Compare July 25, 2025 20:04
@zth zth enabled auto-merge (squash) July 25, 2025 20:05
@zth zth merged commit 7c6f354 into master Jul 25, 2025
27 checks passed
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.

2 participants