Stabel

Check-in [beb3f5edc2]
Login
Overview
Comment:Fix inexhaustiveness bugs.
Timelines: family | ancestors | descendants | both | int-literals-in-pattern-match
Files: files | file ages | folders
SHA3-256: beb3f5edc2d56ca5dda68e03eb3f22f9da3a150bd23fcf7971b9b1cf514c28c0
User & Date: robin.hansen on 2021-09-22 10:47:49
Other Links: branch diff | manifest | tags
Context
2021-09-23
16:51
Codegen should be fixed. But the exhaustiveness checker still has bugs. check-in: cc2965ccda user: robin.hansen tags: int-literals-in-pattern-match
2021-09-22
10:47
Fix inexhaustiveness bugs. check-in: beb3f5edc2 user: robin.hansen tags: int-literals-in-pattern-match
10:11
TypeChecker is ported over. Exhaustiveness checking tests are failing. check-in: efd95fdaff user: robin.hansen tags: int-literals-in-pattern-match
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/TypeChecker.elm from [4361766d21] to [e970f167c0].

1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164


1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
        _ ->
            Just (InexhaustiveMultiFunction range inexhaustiveStates)


inexhaustivenessCheckHelper : List Type -> Qualifier.TypeMatch -> List ( List Type, InexhaustiveState ) -> List ( List Type, InexhaustiveState )
inexhaustivenessCheckHelper typePrefix typeMatch acc =
    let
        ( t, conds ) =
            case typeMatch of
                Qualifier.TypeMatchInt _ _ ->
                    ( Type.Int, [] )

                Qualifier.TypeMatchType _ t_ conds_ ->
                    ( t_, conds_ )

        typeList =
            typePrefix ++ [ t ]
    in
    if List.any (\( toMatch, state ) -> typeList == toMatch && state == Total) acc then
        acc

    else
        let
            subcases =
                conds
                    |> List.filterMap isRecursiveMatch
                    |> List.foldl (inexhaustivenessCheckHelper typeList) acc

            isRecursiveMatch ( _, _, match ) =
                case match of
                    Qualifier.TypeMatchType _ _ (_ :: _) ->
                        Just match

                    _ ->
                        Nothing

            toAdd =
                case ( t, conds, subcases ) of
                    ( _, [], _ ) ->


                        [ ( typeList, Total ) ]

                    ( Type.Int, _, _ ) ->
                        [ ( typeList, SeenInt ) ]

                    _ ->
                        if List.all (Tuple.second >> (==) Total) subcases then
                            [ ( typeList, Total ) ]

                        else







|


|


|











|



<
<
|

<
<
<

<
<
>
>


|







1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154


1155
1156



1157


1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
        _ ->
            Just (InexhaustiveMultiFunction range inexhaustiveStates)


inexhaustivenessCheckHelper : List Type -> Qualifier.TypeMatch -> List ( List Type, InexhaustiveState ) -> List ( List Type, InexhaustiveState )
inexhaustivenessCheckHelper typePrefix typeMatch acc =
    let
        ( t, intLiteral, conds ) =
            case typeMatch of
                Qualifier.TypeMatchInt _ _ ->
                    ( Type.Int, True, [] )

                Qualifier.TypeMatchType _ t_ conds_ ->
                    ( t_, False, conds_ )

        typeList =
            typePrefix ++ [ t ]
    in
    if List.any (\( toMatch, state ) -> typeList == toMatch && state == Total) acc then
        acc

    else
        let
            subcases =
                conds
                    |> List.map isRecursiveMatch
                    |> List.foldl (inexhaustivenessCheckHelper typeList) acc

            isRecursiveMatch ( _, _, match ) =


                match




            toAdd =


                case ( t, intLiteral, conds ) of
                    ( _, False, [] ) ->
                        [ ( typeList, Total ) ]

                    ( Type.Int, True, [] ) ->
                        [ ( typeList, SeenInt ) ]

                    _ ->
                        if List.all (Tuple.second >> (==) Total) subcases then
                            [ ( typeList, Total ) ]

                        else