Play

Check-in [aee83f3ef4]
Login
Overview
Comment:Fix bug where type checker would remove generic from inferred output of a multi-function, if the same output argument wasn't generic in all branches. All known bugs in typechecker now fixed.
Timelines: family | ancestors | descendants | both | stdlib
Files: files | file ages | folders
SHA3-256: aee83f3ef45559d8d1b649131dd3e34a0adec792a0419c46d7b0b7fa8fd4c447
User & Date: robin.hansen on 2021-04-15 09:55:31
Other Links: branch diff | manifest | tags
Context
2021-04-16
08:24
Include member types of union when printing error message. Also fix implementation of list/fold. Sti... check-in: a29bc5e10b user: robin.hansen tags: stdlib
2021-04-15
09:55
Fix bug where type checker would remove generic from inferred output of a multi-function, if the sam... check-in: aee83f3ef4 user: robin.hansen tags: stdlib
09:32
Fix bug where type checker would infer a nested union as possible input type. Unions are flattened. check-in: 9353390979 user: robin.hansen tags: stdlib
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/TypeChecker.elm from [d9536ea640] to [b8dcd8121c].

244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
...
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
                        [] ->
                            Debug.todo "Default impl doesn't have an input argument"

                        firstType :: _ ->
                            ( Qualifier.TypeMatch SourceLocation.emptyRange firstType [], defaultImpl ) :: initialWhens

        ( inferredWhenTypes, newContext ) =

            List.foldr (inferWhenTypes untypedDef) ( [], context ) whens
                |> Tuple.mapFirst normalizeWhenTypes
                |> (\( wts, ctx ) -> simplifyWhenWordTypes wts ctx)
                |> Tuple.mapFirst (List.map2 Tuple.pair whenPatterns >> List.map replaceFirstTypeWithPatternMatch)
                |> Tuple.mapFirst equalizeWhenTypes
                |> Tuple.mapFirst (\whenTypes -> List.map (constrainGenerics untypedDef.metadata.type_) whenTypes)

        replaceFirstTypeWithPatternMatch ( Qualifier.TypeMatch _ matchType _, typeSignature ) =
................................................................................

                unzip ( left, right ) ( leftAcc, rightAcc ) =
                    ( left :: leftAcc, right :: rightAcc )

                constrainedInputs =
                    List.map2 constrainAndZip firstType.input secondType.input

                constrainedOutputs =
                    List.map2 constrainAndZip firstType.output secondType.output

                ( unzippedFirstInputs, unzippedSecondInputs ) =
                    List.foldr unzip ( [], [] ) constrainedInputs

                ( unzippedFirstOutputs, unzippedSecondOutputs ) =
                    List.foldr unzip ( [], [] ) constrainedOutputs

                newFirstType =
                    { input = unzippedFirstInputs
                    , output = unzippedFirstOutputs
                    }

                newSecondType =
                    { input = unzippedSecondInputs
                    , output = unzippedSecondOutputs
                    }
            in
            equalizeWhenTypesHelper
                remaining
                remappedGenerics
                (newSecondType :: newFirstType :: acc)








>
|







 







<
<
<



<
<
<


|




|







244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
...
518
519
520
521
522
523
524



525
526
527



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
                        [] ->
                            Debug.todo "Default impl doesn't have an input argument"

                        firstType :: _ ->
                            ( Qualifier.TypeMatch SourceLocation.emptyRange firstType [], defaultImpl ) :: initialWhens

        ( inferredWhenTypes, newContext ) =
            whens
                |> List.foldr (inferWhenTypes untypedDef) ( [], context )
                |> Tuple.mapFirst normalizeWhenTypes
                |> (\( wts, ctx ) -> simplifyWhenWordTypes wts ctx)
                |> Tuple.mapFirst (List.map2 Tuple.pair whenPatterns >> List.map replaceFirstTypeWithPatternMatch)
                |> Tuple.mapFirst equalizeWhenTypes
                |> Tuple.mapFirst (\whenTypes -> List.map (constrainGenerics untypedDef.metadata.type_) whenTypes)

        replaceFirstTypeWithPatternMatch ( Qualifier.TypeMatch _ matchType _, typeSignature ) =
................................................................................

                unzip ( left, right ) ( leftAcc, rightAcc ) =
                    ( left :: leftAcc, right :: rightAcc )

                constrainedInputs =
                    List.map2 constrainAndZip firstType.input secondType.input




                ( unzippedFirstInputs, unzippedSecondInputs ) =
                    List.foldr unzip ( [], [] ) constrainedInputs




                newFirstType =
                    { input = unzippedFirstInputs
                    , output = firstType.output
                    }

                newSecondType =
                    { input = unzippedSecondInputs
                    , output = secondType.output
                    }
            in
            equalizeWhenTypesHelper
                remaining
                remappedGenerics
                (newSecondType :: newFirstType :: acc)