Stabel

Check-in [a093546b3d]
Login
Overview
Comment:Add 'exposed' field to qualified ast types.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: a093546b3db472cb7557773ab0cee1d3c2949f4c0373357dabb369dc7a2a2ddc
User & Date: robin.hansen on 2021-05-26 18:26:26
Other Links: branch diff | manifest | tags
Context
2021-05-27
09:48
Qualifier now respects (non-)exposed types. check-in: 493d6a6a8b user: robin.hansen tags: module-definition
2021-05-26
18:26
Add 'exposed' field to qualified ast types. check-in: a093546b3d user: robin.hansen tags: module-definition
17:53
Detect required modules from type definitions, type signatures and type matches. check-in: 8d4e3a7233 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Qualifier.elm from [001144993a] to [63ed9445bb].

15
16
17
18
19
20
21

22

23
24
25
26
27
28
29
30
31
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
...
166
167
168
169
170
171
172
173
174
175
176
177
178

179

180
181
182
183


184
185
186
187
188
189
190
191
192
193
194
195



196
197
198
199
200
201
202
...
205
206
207
208
209
210
211
212








213
214
215
216
217
218
219



220
221
222
223
224
225
226
227
228
229
230
231
232








233
234
235
236
237
238
239
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
....
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021

type alias AST =
    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }



type TypeDefinition

    = CustomTypeDef String SourceLocationRange (List String) (List ( String, Type ))
    | UnionTypeDef String SourceLocationRange (List String) (List Type)


type alias WordDefinition =
    { name : String
    , metadata : Metadata
    , implementation : WordImplementation
    }
................................................................................
        _ ->
            Err <| typeErrors ++ wordErrors


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition
resolveUnionInTypeDefs qt td =
    case td of
        CustomTypeDef name range generics members ->
            CustomTypeDef name range generics (List.map (Tuple.mapSecond (resolveUnion qt)) members)

        UnionTypeDef name range generics memberTypes ->
            UnionTypeDef name range generics (List.map (resolveUnion qt) memberTypes)


resolveUnion : Dict String TypeDefinition -> Type -> Type
resolveUnion typeDefs type_ =
    case type_ of
        Type.Custom typeName ->
            case Dict.get typeName typeDefs of
                Just (UnionTypeDef _ _ _ members) ->
                    Type.Union members

                _ ->
                    type_

        Type.CustomGeneric typeName types ->
            case Dict.get typeName typeDefs of
                Just (UnionTypeDef _ _ generics members) ->
                    let
                        genericsMap =
                            List.map2 Tuple.pair generics types
                                |> Dict.fromList

                        rebindGenerics t =
                            case t of
................................................................................
qualifyType :
    RunConfig
    -> Parser.TypeDefinition
    -> ( List Problem, Dict String TypeDefinition )
    -> ( List Problem, Dict String TypeDefinition )
qualifyType config typeDef ( errors, acc ) =
    let
        modRefs =
            case config.ast.moduleDefinition of
                Parser.Undefined ->
                    { aliases = Dict.empty
                    , imports = Dict.empty
                    }



                Parser.Defined mod ->
                    { aliases = mod.aliases
                    , imports = mod.imports
                    }


    in
    case typeDef of
        Parser.CustomTypeDef range name generics members ->
            let
                qualifiedName =
                    qualifyName config name

                qualifiedMemberResult =
                    List.map (Tuple.mapSecond (qualifyMemberType config modRefs range)) members
                        |> List.map raiseTupleError
                        |> Result.combine




                raiseTupleError ( label, result ) =
                    case result of
                        Ok value ->
                            Ok ( label, value )

                        Err err ->
                            Err err
................................................................................
                Err err ->
                    ( err :: errors
                    , acc
                    )

                Ok qualifiedMembers ->
                    ( errors
                    , Dict.insert qualifiedName (CustomTypeDef qualifiedName range generics qualifiedMembers) acc








                    )

        Parser.UnionTypeDef range name generics memberTypes ->
            let
                qualifiedName =
                    qualifyName config name




                qualifiedMemberTypesResult =
                    List.map (qualifyMemberType config modRefs range) memberTypes
                        |> Result.combine
            in
            case qualifiedMemberTypesResult of
                Err err ->
                    ( err :: errors
                    , acc
                    )

                Ok qualifiedMemberTypes ->
                    ( errors
                    , Dict.insert qualifiedName (UnionTypeDef qualifiedName range generics qualifiedMemberTypes) acc








                    )


qualifyMemberType :
    RunConfig
    -> ModuleReferences
    -> SourceLocationRange
................................................................................

                bindResult =
                    binds
                        |> List.map (qualifyMemberType config modRefs range)
                        |> Result.combine
            in
            case ( Dict.get qualifiedName config.inProgressAST.types, bindResult ) of
                ( Just (CustomTypeDef _ _ [] _), _ ) ->
                    Ok <| Type.Custom qualifiedName

                ( Just (CustomTypeDef _ _ _ _), Ok qualifiedBinds ) ->
                    Ok <| Type.CustomGeneric qualifiedName qualifiedBinds

                ( Just (UnionTypeDef _ _ _ memberTypes), _ ) ->
                    Ok <| Type.Union memberTypes

                _ ->
                    Err <| UnknownTypeRef range qualifiedName

        importsLookup name binds =
            case resolveImportedType config modRefs name of
................................................................................

                bindResult =
                    binds
                        |> List.map (qualifyMemberType config modRefs range)
                        |> Result.combine
            in
            case ( Dict.get qualifiedName config.inProgressAST.types, bindResult ) of
                ( Just (CustomTypeDef _ _ [] _), _ ) ->
                    Ok <| Type.Custom qualifiedName

                ( Just (CustomTypeDef _ _ _ _), Ok qualifiedBinds ) ->
                    Ok <| Type.CustomGeneric qualifiedName qualifiedBinds

                ( Just (UnionTypeDef _ _ _ memberTypes), _ ) ->
                    Ok <| Type.Union memberTypes

                _ ->
                    Err <| UnknownTypeRef range qualifiedName

        Parser.Generic sym ->
            Ok (Type.Generic sym)
................................................................................
    -> ModuleReferences
    -> Parser.TypeMatch
    -> Result Problem TypeMatch
qualifyMatch config qualifiedTypes modRefs typeMatch =
    let
        qualifiedNameToMatch range name patterns =
            case Dict.get name qualifiedTypes of
                Just (CustomTypeDef _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
................................................................................
                    case qualifiedPatternsResult of
                        Ok qualifiedPatterns ->
                            Ok <| TypeMatch range actualType qualifiedPatterns

                        Err err ->
                            Err err

                Just (UnionTypeDef _ _ _ types) ->
                    if List.isEmpty patterns then
                        Ok <| TypeMatch range (Type.Union types) []

                    else
                        Err <| UnionTypeMatchWithPatterns range

                Nothing ->
................................................................................
                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }


typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of
        CustomTypeDef name _ _ _ ->
            name

        UnionTypeDef name _ _ _ ->
            name


qualifyName : RunConfig -> String -> String
qualifyName config name =
    if config.packageName == "" then
        name







>
|
>
|
|







 







|
|

|
|







|







|







 







|


|
|
|
>
|
>

|
|
|
>
>












>
>
>







 







|
>
>
>
>
>
>
>
>







>
>
>












|
>
>
>
>
>
>
>
>







 







|


|


|







 







|


|


|







 







|







 







|







 







|


|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
....
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049

type alias AST =
    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }


type
    TypeDefinition
    -- TODO: Each branch here should take a record. Too many arguments.
    = CustomTypeDef String Bool SourceLocationRange (List String) (List ( String, Type ))
    | UnionTypeDef String Bool SourceLocationRange (List String) (List Type)


type alias WordDefinition =
    { name : String
    , metadata : Metadata
    , implementation : WordImplementation
    }
................................................................................
        _ ->
            Err <| typeErrors ++ wordErrors


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition
resolveUnionInTypeDefs qt td =
    case td of
        CustomTypeDef exposed name range generics members ->
            CustomTypeDef exposed name range generics (List.map (Tuple.mapSecond (resolveUnion qt)) members)

        UnionTypeDef exposed name range generics memberTypes ->
            UnionTypeDef exposed name range generics (List.map (resolveUnion qt) memberTypes)


resolveUnion : Dict String TypeDefinition -> Type -> Type
resolveUnion typeDefs type_ =
    case type_ of
        Type.Custom typeName ->
            case Dict.get typeName typeDefs of
                Just (UnionTypeDef _ _ _ _ members) ->
                    Type.Union members

                _ ->
                    type_

        Type.CustomGeneric typeName types ->
            case Dict.get typeName typeDefs of
                Just (UnionTypeDef _ _ _ generics members) ->
                    let
                        genericsMap =
                            List.map2 Tuple.pair generics types
                                |> Dict.fromList

                        rebindGenerics t =
                            case t of
................................................................................
qualifyType :
    RunConfig
    -> Parser.TypeDefinition
    -> ( List Problem, Dict String TypeDefinition )
    -> ( List Problem, Dict String TypeDefinition )
qualifyType config typeDef ( errors, acc ) =
    let
        ( modRefs, exposes ) =
            case config.ast.moduleDefinition of
                Parser.Undefined ->
                    ( { aliases = Dict.empty
                      , imports = Dict.empty
                      }
                    , Set.empty
                    )

                Parser.Defined mod ->
                    ( { aliases = mod.aliases
                      , imports = mod.imports
                      }
                    , mod.exposes
                    )
    in
    case typeDef of
        Parser.CustomTypeDef range name generics members ->
            let
                qualifiedName =
                    qualifyName config name

                qualifiedMemberResult =
                    List.map (Tuple.mapSecond (qualifyMemberType config modRefs range)) members
                        |> List.map raiseTupleError
                        |> Result.combine

                exposed =
                    Set.isEmpty exposes || Set.member name exposes

                raiseTupleError ( label, result ) =
                    case result of
                        Ok value ->
                            Ok ( label, value )

                        Err err ->
                            Err err
................................................................................
                Err err ->
                    ( err :: errors
                    , acc
                    )

                Ok qualifiedMembers ->
                    ( errors
                    , Dict.insert qualifiedName
                        (CustomTypeDef
                            qualifiedName
                            exposed
                            range
                            generics
                            qualifiedMembers
                        )
                        acc
                    )

        Parser.UnionTypeDef range name generics memberTypes ->
            let
                qualifiedName =
                    qualifyName config name

                exposed =
                    Set.isEmpty exposes || Set.member name exposes

                qualifiedMemberTypesResult =
                    List.map (qualifyMemberType config modRefs range) memberTypes
                        |> Result.combine
            in
            case qualifiedMemberTypesResult of
                Err err ->
                    ( err :: errors
                    , acc
                    )

                Ok qualifiedMemberTypes ->
                    ( errors
                    , Dict.insert qualifiedName
                        (UnionTypeDef
                            qualifiedName
                            exposed
                            range
                            generics
                            qualifiedMemberTypes
                        )
                        acc
                    )


qualifyMemberType :
    RunConfig
    -> ModuleReferences
    -> SourceLocationRange
................................................................................

                bindResult =
                    binds
                        |> List.map (qualifyMemberType config modRefs range)
                        |> Result.combine
            in
            case ( Dict.get qualifiedName config.inProgressAST.types, bindResult ) of
                ( Just (CustomTypeDef _ _ _ [] _), _ ) ->
                    Ok <| Type.Custom qualifiedName

                ( Just (CustomTypeDef _ _ _ _ _), Ok qualifiedBinds ) ->
                    Ok <| Type.CustomGeneric qualifiedName qualifiedBinds

                ( Just (UnionTypeDef _ _ _ _ memberTypes), _ ) ->
                    Ok <| Type.Union memberTypes

                _ ->
                    Err <| UnknownTypeRef range qualifiedName

        importsLookup name binds =
            case resolveImportedType config modRefs name of
................................................................................

                bindResult =
                    binds
                        |> List.map (qualifyMemberType config modRefs range)
                        |> Result.combine
            in
            case ( Dict.get qualifiedName config.inProgressAST.types, bindResult ) of
                ( Just (CustomTypeDef _ _ _ [] _), _ ) ->
                    Ok <| Type.Custom qualifiedName

                ( Just (CustomTypeDef _ _ _ _ _), Ok qualifiedBinds ) ->
                    Ok <| Type.CustomGeneric qualifiedName qualifiedBinds

                ( Just (UnionTypeDef _ _ _ _ memberTypes), _ ) ->
                    Ok <| Type.Union memberTypes

                _ ->
                    Err <| UnknownTypeRef range qualifiedName

        Parser.Generic sym ->
            Ok (Type.Generic sym)
................................................................................
    -> ModuleReferences
    -> Parser.TypeMatch
    -> Result Problem TypeMatch
qualifyMatch config qualifiedTypes modRefs typeMatch =
    let
        qualifiedNameToMatch range name patterns =
            case Dict.get name qualifiedTypes of
                Just (CustomTypeDef _ _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
................................................................................
                    case qualifiedPatternsResult of
                        Ok qualifiedPatterns ->
                            Ok <| TypeMatch range actualType qualifiedPatterns

                        Err err ->
                            Err err

                Just (UnionTypeDef _ _ _ _ types) ->
                    if List.isEmpty patterns then
                        Ok <| TypeMatch range (Type.Union types) []

                    else
                        Err <| UnionTypeMatchWithPatterns range

                Nothing ->
................................................................................
                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }


typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of
        CustomTypeDef name _ _ _ _ ->
            name

        UnionTypeDef name _ _ _ _ ->
            name


qualifyName : RunConfig -> String -> String
qualifyName config name =
    if config.packageName == "" then
        name

Modified src/Play/TypeChecker.elm from [03b15c559b] to [267b56b8c9].

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
initContext : LoadedQualifierAST a -> Context
initContext ast =
    let
        concreteTypes =
            Dict.map
                (\_ t ->
                    case t of
                        Qualifier.CustomTypeDef name range generics members ->
                            CustomTypeDef name range generics members

                        Qualifier.UnionTypeDef name range generics memberTypes ->
                            UnionTypeDef name range generics memberTypes
                )
                ast.types

        genericErrors t =
            let
                collectReferencedGenerics memberTypes =







|


|







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
initContext : LoadedQualifierAST a -> Context
initContext ast =
    let
        concreteTypes =
            Dict.map
                (\_ t ->
                    case t of
                        Qualifier.CustomTypeDef name _ range generics members ->
                            CustomTypeDef name range generics members

                        Qualifier.UnionTypeDef name _ range generics memberTypes ->
                            UnionTypeDef name range generics memberTypes
                )
                ast.types

        genericErrors t =
            let
                collectReferencedGenerics memberTypes =

Modified tests/Test/Qualifier.elm from [bfbd7c2c30] to [6fde867bdb].

188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
...
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
...
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664

665
666
667
668
669
670
671
...
782
783
784
785
786
787
788

789
790
791
792

793
794
795
796

797
798
799
800
801
802
803
...
951
952
953
954
955
956
957

958
959
960
961

962
963
964
965

966
967
968
969

970
971
972
973
974
975
976
....
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207

1208
1209
1210
1211
1212
1213
1214
....
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504
....
1793
1794
1795
1796
1797
1798
1799

1800
1801
1802
1803
1804
1805
1806
....
2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080
2081
....
2276
2277
2278
2279
2280
2281
2282

2283
2284
2285
2286
2287
2288
2289
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"

                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" emptyRange [] []
                                , CustomTypeDef "False" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        MultiImpl
................................................................................
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Bool"

                                        emptyRange
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
                                    , CustomTypeDef "True" emptyRange [] []
                                    , CustomTypeDef "False" emptyRange [] []
                                    , CustomTypeDef "Box"

                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
................................................................................
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Maybe"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
                                    , CustomTypeDef "Nothing" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "with-default"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
................................................................................
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"

                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" emptyRange [] []
                                , CustomTypeDef "False" emptyRange [] []
                                , CustomTypeDef "Box"

                                    emptyRange
                                    []
                                    [ ( "value", boolUnion ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "true?"
................................................................................
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef
                                    "/play/test/some/module/USMoney"

                                    emptyRange
                                    []
                                    qualifiedUsMoneyUnion
                                , CustomTypeDef "/play/test/some/module/Dollar"

                                    emptyRange
                                    []
                                    [ ( "dollar-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Cent"

                                    emptyRange
                                    []
                                    [ ( "cent-value", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "/play/test/some/module/into-cents"
................................................................................
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef
                                    "/play/test/some/module/USMoney"

                                    emptyRange
                                    []
                                    qualifiedUsMoneyUnion
                                , CustomTypeDef "/play/test/some/module/Dollar"

                                    emptyRange
                                    []
                                    [ ( "dollar-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Cent"

                                    emptyRange
                                    []
                                    [ ( "cent-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Wallet"

                                    emptyRange
                                    []
                                    [ ( "user-id", Type.Int )
                                    , ( "value", Type.Union qualifiedUsMoneyUnion )
                                    ]
                                ]
                        , words =
................................................................................
                        genericName =
                            name ++ "Generic"

                        unionName =
                            name ++ "Union"
                    in
                    [ ( name
                      , CustomTypeDef name emptyRange [] []
                      )
                    , ( genericName
                      , CustomTypeDef genericName emptyRange [ "a" ] []
                      )
                    , ( unionName
                      , UnionTypeDef unionName

                            emptyRange
                            []
                            [ Type.Custom name
                            , Type.CustomGeneric genericName [ Type.Generic "a" ]
                            ]
                      )
                    ]
................................................................................
                            }

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "SomeType"
                                      , CustomTypeDef "SomeType"

                                            emptyRange
                                            []
                                            [ ( "tipe", Type.Custom "mod/Tipe" ) ]
                                      )
                                    ]
                            , words = Dict.empty
                            }
................................................................................
                            }

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "SomeType"
                                      , CustomTypeDef "SomeType"

                                            emptyRange
                                            []
                                            [ ( "tipe", Type.Custom "/external/package/mod/Tipe" ) ]
                                      )
                                    ]
                            , words = Dict.empty
                            }
................................................................................

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "Tepip"
                                      , CustomTypeDef
                                            "Tepip"

                                            emptyRange
                                            []
                                            [ ( "first", Type.Custom "/external/package/mod/Tipe" )
                                            , ( "second", Type.Custom "internal/mod/Tope" )
                                            ]
                                      )
                                    ]
................................................................................

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "Tepip"
                                      , CustomTypeDef
                                            "Tepip"

                                            emptyRange
                                            []
                                            [ ( "first", Type.Custom "/external/package/mod/Tipe" )
                                            , ( "second", Type.Custom "internal/mod/Tope" )
                                            ]
                                      )
                                    ]







>





|
|







 







>





|
|

>







 







>





|







 







>





|
|

>







 







>




>




>







 







>




>




>




>







 







|


|



>







 







>







 







>







 







>







 







>







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
...
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
...
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
....
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
....
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
....
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
....
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
....
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    True
                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" True emptyRange [] []
                                , CustomTypeDef "False" True emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        MultiImpl
................................................................................
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Bool"
                                        True
                                        emptyRange
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
                                    , CustomTypeDef "True" True emptyRange [] []
                                    , CustomTypeDef "False" True emptyRange [] []
                                    , CustomTypeDef "Box"
                                        True
                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
................................................................................
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Maybe"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
                                    , CustomTypeDef "Nothing" True emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "with-default"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
................................................................................
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    True
                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" True emptyRange [] []
                                , CustomTypeDef "False" True emptyRange [] []
                                , CustomTypeDef "Box"
                                    True
                                    emptyRange
                                    []
                                    [ ( "value", boolUnion ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "true?"
................................................................................
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef
                                    "/play/test/some/module/USMoney"
                                    True
                                    emptyRange
                                    []
                                    qualifiedUsMoneyUnion
                                , CustomTypeDef "/play/test/some/module/Dollar"
                                    True
                                    emptyRange
                                    []
                                    [ ( "dollar-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Cent"
                                    True
                                    emptyRange
                                    []
                                    [ ( "cent-value", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "/play/test/some/module/into-cents"
................................................................................
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef
                                    "/play/test/some/module/USMoney"
                                    True
                                    emptyRange
                                    []
                                    qualifiedUsMoneyUnion
                                , CustomTypeDef "/play/test/some/module/Dollar"
                                    True
                                    emptyRange
                                    []
                                    [ ( "dollar-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Cent"
                                    True
                                    emptyRange
                                    []
                                    [ ( "cent-value", Type.Int ) ]
                                , CustomTypeDef "/play/test/some/module/Wallet"
                                    True
                                    emptyRange
                                    []
                                    [ ( "user-id", Type.Int )
                                    , ( "value", Type.Union qualifiedUsMoneyUnion )
                                    ]
                                ]
                        , words =
................................................................................
                        genericName =
                            name ++ "Generic"

                        unionName =
                            name ++ "Union"
                    in
                    [ ( name
                      , CustomTypeDef name True emptyRange [] []
                      )
                    , ( genericName
                      , CustomTypeDef genericName True emptyRange [ "a" ] []
                      )
                    , ( unionName
                      , UnionTypeDef unionName
                            True
                            emptyRange
                            []
                            [ Type.Custom name
                            , Type.CustomGeneric genericName [ Type.Generic "a" ]
                            ]
                      )
                    ]
................................................................................
                            }

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "SomeType"
                                      , CustomTypeDef "SomeType"
                                            True
                                            emptyRange
                                            []
                                            [ ( "tipe", Type.Custom "mod/Tipe" ) ]
                                      )
                                    ]
                            , words = Dict.empty
                            }
................................................................................
                            }

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "SomeType"
                                      , CustomTypeDef "SomeType"
                                            True
                                            emptyRange
                                            []
                                            [ ( "tipe", Type.Custom "/external/package/mod/Tipe" ) ]
                                      )
                                    ]
                            , words = Dict.empty
                            }
................................................................................

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "Tepip"
                                      , CustomTypeDef
                                            "Tepip"
                                            True
                                            emptyRange
                                            []
                                            [ ( "first", Type.Custom "/external/package/mod/Tipe" )
                                            , ( "second", Type.Custom "internal/mod/Tope" )
                                            ]
                                      )
                                    ]
................................................................................

                        expectedAst =
                            { types =
                                Dict.fromList
                                    [ ( "Tepip"
                                      , CustomTypeDef
                                            "Tepip"
                                            True
                                            emptyRange
                                            []
                                            [ ( "first", Type.Custom "/external/package/mod/Tipe" )
                                            , ( "second", Type.Custom "internal/mod/Tope" )
                                            ]
                                      )
                                    ]

Modified tests/Test/Qualifier/Util.elm from [f95a80eea4] to [d1d2da2384].

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204


addFunctionsForStructs : AST -> AST
addFunctionsForStructs ast =
    let
        helper _ t wipAst =
            case t of
                AST.CustomTypeDef name _ generics members ->
                    addFunctionsForStructsHelper name generics members wipAst

                _ ->
                    wipAst
    in
    Dict.foldl helper ast ast.types

................................................................................
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition
stripTypeLocation typeDef =
    case typeDef of
        AST.CustomTypeDef name _ generics members ->
            AST.CustomTypeDef name emptyRange generics members

        AST.UnionTypeDef name _ generics members ->
            AST.UnionTypeDef name emptyRange generics members


stripWordLocation : WordDefinition -> WordDefinition
stripWordLocation word =
    { word
        | implementation = stripImplementationLocation word.implementation
        , metadata = Metadata.clearSourceLocationRange word.metadata







|







 







|
|

|
|







108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204


addFunctionsForStructs : AST -> AST
addFunctionsForStructs ast =
    let
        helper _ t wipAst =
            case t of
                AST.CustomTypeDef name _ _ generics members ->
                    addFunctionsForStructsHelper name generics members wipAst

                _ ->
                    wipAst
    in
    Dict.foldl helper ast ast.types

................................................................................
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition
stripTypeLocation typeDef =
    case typeDef of
        AST.CustomTypeDef exposed name _ generics members ->
            AST.CustomTypeDef exposed name emptyRange generics members

        AST.UnionTypeDef exposed name _ generics members ->
            AST.UnionTypeDef exposed name emptyRange generics members


stripWordLocation : WordDefinition -> WordDefinition
stripWordLocation word =
    { word
        | implementation = stripImplementationLocation word.implementation
        , metadata = Metadata.clearSourceLocationRange word.metadata

Modified tests/Test/TypeChecker.elm from [51729be1c5] to [5cf7f1ff07].

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
299
300
301
302
303
304
305

306
307
308
309
310
311
312
...
337
338
339
340
341
342
343

344
345
346
347
348
349
350
...
411
412
413
414
415
416
417

418
419
420
421
422
423

424
425
426
427

428
429
430
431
432
433
434
435
436
437
438
439
440
...
601
602
603
604
605
606
607




608
609
610
611
612
613
614
615
...
620
621
622
623
624
625
626




627
628
629
630
631
632
633
634
...
645
646
647
648
649
650
651

652
653
654
655
656
657
658
659
660
661
662
663
664
665
...
794
795
796
797
798
799
800

801
802
803
804
805
806

807
808
809
810

811
812
813
814
815
816
817
...
878
879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896
897
898
...
949
950
951
952
953
954
955

956
957
958
959
960
961

962
963
964
965
966
967




968
969
970
971
972
973
974
....
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035




1036
1037
1038
1039
1040
1041
1042
....
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162




1163
1164
1165
1166
1167
1168
1169
....
1410
1411
1412
1413
1414
1415
1416

1417
1418
1419
1420
1421
1422




1423
1424
1425
1426
1427
1428
1429
....
1489
1490
1491
1492
1493
1494
1495

1496
1497
1498
1499
1500
1501

1502
1503
1504
1505
1506
1507




1508
1509
1510
1511
1512
1513
1514
                        Expect.fail "Did not expect type check to succeed."
        , test "Custom data structure without fields" <|
            \_ ->
                let
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "True" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "as-int"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
................................................................................
                        Expect.pass
        , test "Custom data structure with fields" <|
            \_ ->
                let
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Person" emptyRange [] [ ( "age", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc-age"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Person" ] [ Type.Custom "Person" ]
................................................................................
        , test "Generic custom type" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box"

                                    emptyRange
                                    [ "a" ]
                                    [ ( "element", Type.Generic "a" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "Generic types with rotations and quotations" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Coordinate"

                                    emptyRange
                                    []
                                    [ ( "x", Type.Int )
                                    , ( "y", Type.Int )
                                    ]
                                ]
                        , words =
................................................................................
                        , Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ]
                        ]

                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Pair"

                                    emptyRange
                                    [ "a", "b" ]
                                    [ ( "first", Type.Generic "a" )
                                    , ( "second", Type.Generic "b" )
                                    ]
                                , QAST.UnionTypeDef "List"

                                    emptyRange
                                    [ "a" ]
                                    listUnion
                                , QAST.CustomTypeDef "NonEmpty"

                                    emptyRange
                                    [ "a" ]
                                    [ ( "head", Type.Generic "a" )
                                    , ( "rest", Type.Union listUnion )
                                    ]
                                , QAST.CustomTypeDef "Empty" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
................................................................................
                        Expect.pass
        , test "Generic custom type fails if not generic is listed" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName




                                [ QAST.CustomTypeDef "Box" emptyRange [] [ ( "element", Type.Generic "a" ) ]
                                ]
                        , words =
                            Dict.empty
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
................................................................................
                        Expect.pass
        , test "Generic custom type fails if wrong generic is listed" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName




                                [ QAST.CustomTypeDef "Box" emptyRange [ "a" ] [ ( "element", Type.Generic "b" ) ]
                                ]
                        , words =
                            Dict.empty
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
................................................................................
                        , Type.Custom "False"
                        ]

                template multiFn =
                    { types =
                        Dict.fromListBy QAST.typeDefinitionName
                            [ QAST.UnionTypeDef "Bool"

                                emptyRange
                                []
                                [ Type.Custom "True"
                                , Type.Custom "False"
                                ]
                            , QAST.CustomTypeDef "True" emptyRange [] []
                            , QAST.CustomTypeDef "False" emptyRange [] []
                            ]
                    , words =
                        Dict.fromListBy .name
                            [ multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
................................................................................
            , test "When returning union" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Beings"

                                        emptyRange
                                        []
                                        [ Type.Custom "Person"
                                        , Type.Custom "Dog"
                                        ]
                                    , QAST.CustomTypeDef "Person"

                                        emptyRange
                                        []
                                        [ ( "age", Type.Int ) ]
                                    , QAST.CustomTypeDef "Dog"

                                        emptyRange
                                        []
                                        [ ( "man-years", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "add-to-age"
................................................................................
            , test "Function requiring a concrete type should not accept an union with that type" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Bool"

                                        emptyRange
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
                                    , QAST.CustomTypeDef "True" emptyRange [] []
                                    , QAST.CustomTypeDef "False" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                , Type.Custom "EmptyList"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "List"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ]
                                        , Type.Custom "EmptyList"
                                        ]
                                    , QAST.CustomTypeDef "NonEmptyList"

                                        emptyRange
                                        [ "a" ]
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []




                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "first-or-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []




                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "with-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
            , test "Generic union fails if not generic is listed" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "b"
                                        , Type.Custom "Nothing"
                                        ]
                                    , QAST.CustomTypeDef "Nothing" emptyRange [] []




                                    ]
                            , words =
                                Dict.empty
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []




                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "map"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
                                , Type.Custom "EmptyList"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "List"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ]
                                        , Type.Custom "EmptyList"
                                        ]
                                    , QAST.CustomTypeDef "NonEmptyList"

                                        emptyRange
                                        [ "a" ]
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []




                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "sum"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.SoloImpl







|







 







|







 







>







 







>







 







>






>




>





|







 







>
>
>
>
|







 







>
>
>
>
|







 







>





|
|







 







>






>




>







 







>





|
|







 







>






>





|
>
>
>
>







 







>





|
>
>
>
>







 







>





|
>
>
>
>







 







>





|
>
>
>
>







 







>






>





|
>
>
>
>







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
...
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
...
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
...
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
...
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
...
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
....
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
....
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
....
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
....
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
                        Expect.fail "Did not expect type check to succeed."
        , test "Custom data structure without fields" <|
            \_ ->
                let
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "True" True emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "as-int"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
................................................................................
                        Expect.pass
        , test "Custom data structure with fields" <|
            \_ ->
                let
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Person" True emptyRange [] [ ( "age", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc-age"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Person" ] [ Type.Custom "Person" ]
................................................................................
        , test "Generic custom type" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box"
                                    True
                                    emptyRange
                                    [ "a" ]
                                    [ ( "element", Type.Generic "a" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "Generic types with rotations and quotations" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Coordinate"
                                    True
                                    emptyRange
                                    []
                                    [ ( "x", Type.Int )
                                    , ( "y", Type.Int )
                                    ]
                                ]
                        , words =
................................................................................
                        , Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ]
                        ]

                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Pair"
                                    True
                                    emptyRange
                                    [ "a", "b" ]
                                    [ ( "first", Type.Generic "a" )
                                    , ( "second", Type.Generic "b" )
                                    ]
                                , QAST.UnionTypeDef "List"
                                    True
                                    emptyRange
                                    [ "a" ]
                                    listUnion
                                , QAST.CustomTypeDef "NonEmpty"
                                    True
                                    emptyRange
                                    [ "a" ]
                                    [ ( "head", Type.Generic "a" )
                                    , ( "rest", Type.Union listUnion )
                                    ]
                                , QAST.CustomTypeDef "Empty" True emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
................................................................................
                        Expect.pass
        , test "Generic custom type fails if not generic is listed" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box"
                                    True
                                    emptyRange
                                    []
                                    [ ( "element", Type.Generic "a" ) ]
                                ]
                        , words =
                            Dict.empty
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
................................................................................
                        Expect.pass
        , test "Generic custom type fails if wrong generic is listed" <|
            \_ ->
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box"
                                    True
                                    emptyRange
                                    [ "a" ]
                                    [ ( "element", Type.Generic "b" ) ]
                                ]
                        , words =
                            Dict.empty
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
................................................................................
                        , Type.Custom "False"
                        ]

                template multiFn =
                    { types =
                        Dict.fromListBy QAST.typeDefinitionName
                            [ QAST.UnionTypeDef "Bool"
                                True
                                emptyRange
                                []
                                [ Type.Custom "True"
                                , Type.Custom "False"
                                ]
                            , QAST.CustomTypeDef "True" True emptyRange [] []
                            , QAST.CustomTypeDef "False" True emptyRange [] []
                            ]
                    , words =
                        Dict.fromListBy .name
                            [ multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
................................................................................
            , test "When returning union" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Beings"
                                        True
                                        emptyRange
                                        []
                                        [ Type.Custom "Person"
                                        , Type.Custom "Dog"
                                        ]
                                    , QAST.CustomTypeDef "Person"
                                        True
                                        emptyRange
                                        []
                                        [ ( "age", Type.Int ) ]
                                    , QAST.CustomTypeDef "Dog"
                                        True
                                        emptyRange
                                        []
                                        [ ( "man-years", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "add-to-age"
................................................................................
            , test "Function requiring a concrete type should not accept an union with that type" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Bool"
                                        True
                                        emptyRange
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
                                    , QAST.CustomTypeDef "True" True emptyRange [] []
                                    , QAST.CustomTypeDef "False" True emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                , Type.Custom "EmptyList"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "List"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ]
                                        , Type.Custom "EmptyList"
                                        ]
                                    , QAST.CustomTypeDef "NonEmptyList"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList"
                                        True
                                        emptyRange
                                        []
                                        []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "first-or-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil"
                                        True
                                        emptyRange
                                        []
                                        []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "with-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
            , test "Generic union fails if not generic is listed" <|
                \_ ->
                    let
                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "b"
                                        , Type.Custom "Nothing"
                                        ]
                                    , QAST.CustomTypeDef "Nothing"
                                        True
                                        emptyRange
                                        []
                                        []
                                    ]
                            , words =
                                Dict.empty
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "Maybe"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil"
                                        True
                                        emptyRange
                                        []
                                        []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "map"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
................................................................................
                                , Type.Custom "EmptyList"
                                ]

                        input =
                            { types =
                                Dict.fromListBy QAST.typeDefinitionName
                                    [ QAST.UnionTypeDef "List"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ]
                                        , Type.Custom "EmptyList"
                                        ]
                                    , QAST.CustomTypeDef "NonEmptyList"
                                        True
                                        emptyRange
                                        [ "a" ]
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList"
                                        True
                                        emptyRange
                                        []
                                        []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "sum"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.SoloImpl

Modified tests/Test/TypeChecker/Error.elm from [59a5248785] to [8ad155b434].

19
20
21
22
23
24
25

26
27
28
29
30
31
32
..
84
85
86
87
88
89
90

91
92
93
94
95
96
97
...
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
342
343
344
345
346
347
348

349
350
351
352
353
354
355
...
516
517
518
519
520
521
522

523
524
525
526
527
528

529
530
531
532
533
534
535
536
537
538
539
        [ test "Undeclared generic" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ CustomTypeDef "Box"

                                    emptyRange
                                    [ "a" ]
                                    [ ( "value", Type.Generic "b" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "Unexpected function" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ CustomTypeDef "IntBox"

                                    emptyRange
                                    []
                                    [ ( "value", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "An inferred union output type should not successfully type check against a generic variable" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"

                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" emptyRange [] []
                                , CustomTypeDef "False" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Generic "out" ]
................................................................................
            , test "Nested" <|
                \_ ->
                    let
                        ast =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ CustomTypeDef "IntBox"

                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Maybe"

                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef "IntBox"

                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    , CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nil" ]







>







 







>







 







>





|
|







 







>







 







>






>



|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
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
        [ test "Undeclared generic" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ CustomTypeDef "Box"
                                    False
                                    emptyRange
                                    [ "a" ]
                                    [ ( "value", Type.Generic "b" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "Unexpected function" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ CustomTypeDef "IntBox"
                                    False
                                    emptyRange
                                    []
                                    [ ( "value", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
................................................................................
        , test "An inferred union output type should not successfully type check against a generic variable" <|
            \_ ->
                let
                    ast =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    False
                                    emptyRange
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" False emptyRange [] []
                                , CustomTypeDef "False" False emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Generic "out" ]
................................................................................
            , test "Nested" <|
                \_ ->
                    let
                        ast =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ CustomTypeDef "IntBox"
                                        False
                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
................................................................................
                                , Type.Custom "Nil"
                                ]

                        input =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Maybe"
                                        False
                                        emptyRange
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef "IntBox"
                                        False
                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    , CustomTypeDef "Nil" False emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nil" ]