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

Type inference error with Tuples and float/ints #697

Closed
bengolds opened this issue May 23, 2022 · 1 comment · Fixed by #721
Closed

Type inference error with Tuples and float/ints #697

bengolds opened this issue May 23, 2022 · 1 comment · Fixed by #721
Assignees
Labels
bug Something isn't working type inference Related to type inference

Comments

@bengolds
Copy link
Contributor

If you destructure a number from a tuple, the type-inference seems to not be able to treat it as both a float and an int.

module Main exposing (foo)

foo asInt =
    let
        myGoodNumber =
            216

        ( myBadNumber, _ ) =
            ( 216, 0 )
    in

    if asInt then
        String.fromInt myGoodNumber
            ++ String.fromInt myBadNumber

    else
        String.fromFloat myGoodNumber
            ++ String.fromFloat myBadNumber

Expected Behavior

elm make doesn't compile with any errors here.

Current Behavior

elm-language-server throws an error:
CleanShot 2022-05-23 at 13 28 32@2x

Context

It seems that Elm does some type-punning for constant numbers, and lets them be both Floats and Ints. The type inference code here seems to mostly do the same thing, except when destructuring those numbers. Perhaps this breaks for record and opaque type destructuring as well?

@razzeee
Copy link
Member

razzeee commented May 23, 2022

FYI @jmbockhorst

@jmbockhorst jmbockhorst added bug Something isn't working type inference Related to type inference labels Jun 30, 2022
@jmbockhorst jmbockhorst self-assigned this Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working type inference Related to type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants