Skip to content

Wrong type inference #2151

Open
Open
@Birowsky

Description

@Birowsky

Given:

apiUrl : ApiEndpoint
apiUrl = global.config.apiUrl

Compiler fails with:

Something is off with the body of the `apiUrl` definition:  
	156|                     global.config.apiUrl                          
	                         ^^^^^^^^^^^^^^^^^^^^ 
The value at .apiUrl is a:
      String  
But the type annotation on `apiUrl` says it should be:
      ApiEndpoint

Which is wrong because global.config.apiUrl is indeed of type ApiEndpoint.

Some more context:

type ApiEndpoint = ApiEndpoint String
type alias Config = ConfigWithTaggedApiUrl ConfigArgs
type alias ConfigWithTaggedApiUrl a = { a | apiUrl : ApiEndpoint }
type alias ConfigArgs =
    { googleMapApiKey : String
    , iosGoogleClientId : String
    , androidGoogleClientId : String
    , sentryId : String
    , gtmId : String
    , facebookId : String
    , appUrl : String
    , apiUrl : String
    , staticUrl : String
    , googleAppNumber : String
    , privacyPolicyUrl : String
    , termsOfUseUrl : String
    , cognito : CognitoConfig
    , appleAppStoreUrl : String
    , googlePlayStoreUrl : String
    }

Potentially useful finding:
This issue occurs when the code looks like this:

update global msg state =
    case msg of
        SomeMsg ->
            let
                apiUrl2 : ApiEndpoint
                apiUrl2 =
                    global.config.apiUrl

But it doesn't when it looks like so:

update global msg state =
    let
        apiUrl2 : ApiEndpoint
        apiUrl2 =
            global.config.apiUrl
    in
    case msg of
        SomeMsg ->

I am unfortunately unable to provide an SSCCE at this time because this is too big of an application. Please ask if I can provide further useful info.

  • Elm: 19.1
  • Operating System: Mac 11.0.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions