Play

Check-in [e9d8932285]
Login
Overview
Comment:Simplify tests by automating ctor and getter/setter boilerplate.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e9d8932285aef6d47f93f7a2e10261d804f9caa33924fc96e12d468df6c13d65
User & Date: robin.hansen on 2021-01-17 10:32:49
Other Links: manifest | tags
Context
2021-01-24
07:22
Make syntax changes based on language proposal [49d490f836]. Fixes tickets [05dc3c652b], [2ed5dbbb6d... check-in: 5de766c3d5 user: robin.hansen tags: trunk
2021-01-19
16:09
deftype: is now defstruct:. Disabled source location test, with intention of enabling it after all s... check-in: 1757d09f8c user: robin.hansen tags: alpha2-syntax-changes
2021-01-17
10:32
Simplify tests by automating ctor and getter/setter boilerplate. check-in: e9d8932285 user: robin.hansen tags: trunk
2020-11-19
05:57
Fix 'Quotations' example in play ground. check-in: fc5483d159 user: robin.hansen tags: trunk, alpha-1, releases
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/Parser.elm from [4f58041fce] to [4e42e708d8].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
203
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
...
356
357
358
359
360
361
362

363
364
365
366
367
368
369
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
...
418
419
420
421
422
423
424

425
426
427
428
429
430
431
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
...
521
522
523
524
525
526
527

528
529
530
531
532
533
534
...
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
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
import Dict.Extra as Dict
import Expect
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (SourceLocation, SourceLocationRange, emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST exposing (..)
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (compile, compileRetainLocations)


suite : Test
suite =
    describe "Parser"
        [ test "Sample program" <|
            \_ ->
................................................................................
                        expectedAst =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange "True" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">True"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "True" ]
                                      }
                                    , { name = "as-int"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "True" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.Integer emptyRange 1
                                                ]
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        []
                                        [ ( "age", Type.Int )
                                        , ( "jobs", Type.Int )
                                        ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Person"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Int, Type.Int ] [ Type.Custom "Person" ]
                                      , implementation =
                                            SoloImpl [ AST.ConstructType "Person" ]
                                      }
                                    , { name = "age>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Custom "Person" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl [ AST.GetMember "Person" "age" ]
                                      }
                                    , { name = ">age"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Custom "Person", Type.Int ] [ Type.Custom "Person" ]
                                      , implementation =
                                            SoloImpl [ AST.SetMember "Person" "age" ]
                                      }
                                    , { name = ">jobs"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Custom "Person", Type.Int ] [ Type.Custom "Person" ]
                                      , implementation =
                                            SoloImpl [ AST.SetMember "Person" "jobs" ]
                                      }
                                    , { name = "jobs>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Custom "Person" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl [ AST.GetMember "Person" "jobs" ]
                                      }
                                    , { name = "get-age"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Person" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.Word emptyRange "age>"
                                                ]
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "False"
                                        ]
                                    , CustomTypeDef emptyRange "True" [] []
                                    , CustomTypeDef emptyRange "False" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">True"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "True"
                                                ]
                                      }
                                    , { name = ">False"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "False" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "False"
                                                ]
                                      }
                                    , { name = "to-int"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ AST.Word emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "False") []
................................................................................
                                                  , [ AST.Word emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "if-present"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ AST.Word emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "Nil") []
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Box" [ "a" ] [ ( "element", Type.Generic "a" ) ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Box"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Generic "a" ]
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ] ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "Box"
                                                ]
                                      }
                                    , { name = ">element"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    , Type.Generic "a"
                                                    ]
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.SetMember "Box" "element"
                                                ]
                                      }
                                    , { name = "element>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    ]
                                                    [ Type.Generic "a"
                                                    ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.GetMember "Box" "element"
                                                ]
                                      }
                                    , { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "if-present"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.CustomGeneric "Box" [ Type.Generic "a" ]) []
                                                  , [ AST.Word emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "Nil") []
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Box" [ "a" ] [ ( "element", Type.Generic "a" ) ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Box"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [ Type.Generic "a" ]
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ] ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "Box"
                                                ]
                                      }
                                    , { name = ">element"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    , Type.Generic "a"
                                                    ]
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.SetMember "Box" "element"
                                                ]
                                      }
                                    , { name = "element>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType
                                                    [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                                    ]
                                                    [ Type.Generic "a"
                                                    ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.GetMember "Box" "element"
                                                ]
                                      }
                                    , { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "if-present"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "MaybeBox" [ Type.Generic "a" ], Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            MultiImpl
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }

                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast







|







 







<
<
<
<
<
<
<
<
|










>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|










>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
92
93
94
95
96
97
98








99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
137
138
139
140
141
142
143



































144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
282
283
284
285
286
287
288


















289
290
291
292
293
294
295
296
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
336
337
338
339
340
341
342









343
344
345
346
347
348
349
350
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
394
395
396
397
398
399
400














































401
402
403
404
405
406
407
408
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
...
453
454
455
456
457
458
459














































460
461
462
463
464
465
466
467
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
import Dict.Extra as Dict
import Expect
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (SourceLocation, SourceLocationRange, emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST exposing (..)
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (addFunctionsForStructs, compile, compileRetainLocations)


suite : Test
suite =
    describe "Parser"
        [ test "Sample program" <|
            \_ ->
................................................................................
                        expectedAst =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange "True" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name








                                    [ { name = "as-int"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "True" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.Integer emptyRange 1
                                                ]
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        []
                                        [ ( "age", Type.Int )
                                        , ( "jobs", Type.Int )
                                        ]
                                    ]
                            , words =
                                Dict.fromListBy .name



































                                    [ { name = "get-age"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Person" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl
                                                [ AST.Word emptyRange "age>"
                                                ]
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "False"
                                        ]
                                    , CustomTypeDef emptyRange "True" [] []
                                    , CustomTypeDef emptyRange "False" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name


















                                    [ { name = "to-int"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ AST.Word emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "False") []
................................................................................
                                                  , [ AST.Word emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name









                                    [ { name = "if-present"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ AST.Word emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "Nil") []
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Box" [ "a" ] [ ( "element", Type.Generic "a" ) ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name














































                                    [ { name = "if-present"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.CustomGeneric "Box" [ Type.Generic "a" ]) []
                                                  , [ AST.Word emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "Nil") []
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast
................................................................................
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef emptyRange "Box" [ "a" ] [ ( "element", Type.Generic "a" ) ]
                                    , CustomTypeDef emptyRange "Nil" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name














































                                    [ { name = "if-present"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "MaybeBox" [ Type.Generic "a" ], Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            MultiImpl
................................................................................
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

                        Ok ast ->
                            Expect.equal expectedAst ast

Modified tests/Test/Parser/Util.elm from [cc3243c80a] to [240dab60e8].

1

2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
..
94
95
96
97
98
99
100




































































module Test.Parser.Util exposing

    ( compile
    , compileRetainLocations
    )

import Dict
import Dict.Extra as Dict
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)

import Play.Parser as AST exposing (..)
import Play.Parser.Problem exposing (Problem)
import String.Extra as String


compile : String -> Result (List Problem) AST
compile str =
................................................................................
stripRecursiveTypeMatchLocation typeMatchValue =
    case typeMatchValue of
        RecursiveMatch typeMatch ->
            RecursiveMatch (stripTypeMatchLocation typeMatch)

        _ ->
            typeMatchValue





































































>
|







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
module Test.Parser.Util exposing
    ( addFunctionsForStructs
    , compile
    , compileRetainLocations
    )

import Dict
import Dict.Extra as Dict
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type exposing (Type)
import Play.Parser as AST exposing (..)
import Play.Parser.Problem exposing (Problem)
import String.Extra as String


compile : String -> Result (List Problem) AST
compile str =
................................................................................
stripRecursiveTypeMatchLocation typeMatchValue =
    case typeMatchValue of
        RecursiveMatch typeMatch ->
            RecursiveMatch (stripTypeMatchLocation typeMatch)

        _ ->
            typeMatchValue


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


addFunctionsForStructsHelper : String -> List String -> List ( String, Type ) -> AST -> AST
addFunctionsForStructsHelper name generics members ast =
    let
        selfType =
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =
            { name = ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =
            List.map settersHelper members

        settersHelper ( memberName, type_ ) =
            { name = ">" ++ memberName
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType
                        [ selfType, type_ ]
                        [ selfType ]
            , implementation =
                AST.SoloImpl [ AST.SetMember name memberName ]
            }

        getters =
            List.map gettersHelper members

        gettersHelper ( memberName, type_ ) =
            { name = memberName ++ ">"
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType
                        [ selfType ]
                        [ type_ ]
            , implementation =
                AST.SoloImpl [ AST.GetMember name memberName ]
            }

        allFuncs =
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }

Modified tests/Test/Qualifier.elm from [2c8c1954f5] to [fe9a3dfa3e].

6
7
8
9
10
11
12


13
14
15
16
17
18
19
...
163
164
165
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
203
204
205
...
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
240
241
242

243
244
245
246
247
248
249
...
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
...
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

646
647
648
649
650
651
652
...
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728

729
730
731
732
733
734
735
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
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
813
814
815
816
817
818
...
820
821
822
823
824
825
826

827
828
829
830
831
832
833
...
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
...
900
901
902
903
904
905
906

907
908
909
910
911
912
913
914
import Play.Data.Builtin as Builtin
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST
import Play.Qualifier exposing (..)
import Test exposing (Test, describe, test)




suite : Test
suite =
    describe "Qualifier"
        [ test "Simple program" <|
            \_ ->
................................................................................
                                    , Type.Custom "False"
                                    ]
                                , AST.CustomTypeDef emptyRange "True" [] []
                                , AST.CustomTypeDef emptyRange "False" [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Custom "True" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.ConstructType "True"
                                            ]
                                  }
                                , { name = ">False"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Custom "False" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.ConstructType "False"
                                            ]
                                  }
                                , { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange (Type.Custom "False") [], [ AST.Integer emptyRange 0 ] )
                                            , ( AST.TypeMatch emptyRange (Type.Custom "True") [], [ AST.Integer emptyRange 1 ] )
                                            ]
                                            []
                                  }
                                ]
                        }


                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    emptyRange
                                    []
................................................................................
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" emptyRange [] []
                                , CustomTypeDef "False" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Custom "True" ]
                                  , implementation =
                                        SoloImpl
                                            [ ConstructType "True"
                                            ]
                                  }
                                , { name = ">False"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Custom "False" ]
                                  , implementation =
                                        SoloImpl
                                            [ ConstructType "False"
                                            ]
                                  }
                                , { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (Type.Custom "False") [], [ Integer emptyRange 0 ] )
                                            , ( TypeMatch emptyRange (Type.Custom "True") [], [ Integer emptyRange 1 ] )
                                            ]
                                            []
                                  }
                                ]
                        }

                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
................................................................................
                                    , AST.CustomTypeDef emptyRange
                                        "Box"
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">True"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "True" ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ConstructType "True"
                                                ]
                                      }
                                    , { name = ">False"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "False" ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ConstructType "False"
                                                ]
                                      }
                                    , { name = ">Box"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int ] [ Type.Custom "Box" ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ConstructType "Box"
                                                ]
                                      }
                                    , { name = ">value"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int, Type.Custom "Box" ] [ Type.Custom "Box" ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.SetMember "Box" "value"
                                                ]
                                      }
                                    , { name = "<value"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Box" ] [ Type.Int ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.GetMember "Box" "value"
                                                ]
                                      }
                                    , { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Custom "Box") [ ( "value", AST.LiteralInt 0 ) ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }


                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Bool"
                                        emptyRange
                                        []
................................................................................
                                    , CustomTypeDef "Box"
                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">True"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "True" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "True"
                                                ]
                                      }
                                    , { name = ">False"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "False" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "False"
                                                ]
                                      }
                                    , { name = ">Box"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int ] [ Type.Custom "Box" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Box"
                                                ]
                                      }
                                    , { name = ">value"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int, Type.Custom "Box" ] [ Type.Custom "Box" ]
                                      , implementation =
                                            SoloImpl
                                                [ SetMember "Box" "value"
                                                ]
                                      }
                                    , { name = "<value"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Box" ] [ Type.Int ]
                                      , implementation =
                                            SoloImpl
                                                [ GetMember "Box" "value"
                                                ]
                                      }
                                    , { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "Box") [ ( "value", LiteralInt 0 ) ], [ Word emptyRange ">True" ] )
                                                ]
                                                [ Word emptyRange ">False" ]
                                      }
                                    ]
                            }

                    in
                    case run unqualifiedAst of
                        Err _ ->
                            Expect.fail "Did not expect qualification to fail"

                        Ok qualifiedAst ->
                            Expect.equal expectedAst qualifiedAst
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
                                    , AST.CustomTypeDef emptyRange "Nothing" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nothing"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nothing" ]
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ConstructType "Nothing"
                                                ]
                                      }
                                    , { name = "with-default"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "swap"
                                                , AST.Word emptyRange "drop"
                                                ]
                                      }
                                    ]
                            }


                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Maybe"
                                        emptyRange
                                        [ "a" ]
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
                                    , CustomTypeDef "Nothing" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nothing"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nothing" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Nothing"
                                                ]
                                      }
                                    , { name = "with-default"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ Builtin emptyRange Builtin.StackDrop ]
                                                  )
                                                ]
                                                [ Builtin emptyRange Builtin.StackSwap
                                                , Builtin emptyRange Builtin.StackDrop
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run unqualifiedAst of
                        Err _ ->
                            Expect.fail "Did not expect qualification to fail"

                        Ok qualifiedAst ->
                            Expect.equal expectedAst qualifiedAst
................................................................................
                                , AST.CustomTypeDef emptyRange
                                    "Box"
                                    []
                                    [ ( "value", Type.Custom "Bool" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.ConstructType "True"
                                            ]
                                  }
                                , { name = ">False"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "False" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.ConstructType "False"
                                            ]
                                  }
                                , { name = ">Box"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [ Type.Custom "Bool" ] [ Type.Custom "Box" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.ConstructType "Box"
                                            ]
                                  }
                                , { name = ">value"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType
                                                [ Type.Custom "Bool", Type.Custom "Box" ]
                                                [ Type.Custom "Box" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.SetMember "Box" "value"
                                            ]
                                  }
                                , { name = "<value"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [ Type.Custom "Box" ] [ Type.Custom "Bool" ]
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.GetMember "Box" "value"
                                            ]
                                  }
                                , { name = "true?"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ Type.Custom "Bool" ]
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange
                                                    (Type.Custom "Box")
................................................................................
                                              , [ AST.Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ AST.Word emptyRange ">False" ]
                                  }
                                ]
                        }


                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    emptyRange
                                    []
................................................................................
                                , CustomTypeDef "Box"
                                    emptyRange
                                    []
                                    [ ( "value", boolUnion ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                  , implementation =
                                        SoloImpl
                                            [ ConstructType "True"
                                            ]
                                  }
                                , { name = ">False"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "False" ]
                                  , implementation =
                                        SoloImpl
                                            [ ConstructType "False"
                                            ]
                                  }
                                , { name = ">Box"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [ boolUnion ] [ Type.Custom "Box" ]
                                  , implementation =
                                        SoloImpl
                                            [ ConstructType "Box"
                                            ]
                                  }
                                , { name = ">value"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [ boolUnion, Type.Custom "Box" ] [ Type.Custom "Box" ]
                                  , implementation =
                                        SoloImpl
                                            [ SetMember "Box" "value"
                                            ]
                                  }
                                , { name = "<value"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [ Type.Custom "Box" ] [ boolUnion ]
                                  , implementation =
                                        SoloImpl
                                            [ GetMember "Box" "value"
                                            ]
                                  }
                                , { name = "true?"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ boolUnion ]
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange
                                                    (Type.Custom "Box")
................................................................................
                                              , [ Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ Word emptyRange ">False" ]
                                  }
                                ]
                        }

                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
        ]







>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|










>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|










>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|











>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|









>







 







<
<
<
<
<
<
<
<
<
|













>







 







<
<
<
<
<
<
<
<
<
|













>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>








6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
165
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
...
192
193
194
195
196
197
198


















199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
476
477
478
479
480
481
482













































483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
508
509
510
511
512
513
514













































515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
...
542
543
544
545
546
547
548









549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
...
571
572
573
574
575
576
577









578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
621
622
623
624
625
626
627















































628
629
630
631
632
633
634
635
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
...
657
658
659
660
661
662
663













































664
665
666
667
668
669
670
671
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
import Play.Data.Builtin as Builtin
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type
import Play.Parser as AST
import Play.Qualifier exposing (..)
import Test exposing (Test, describe, test)
import Test.Parser.Util as ParserUtil
import Test.Qualifier.Util as QualifierUtil


suite : Test
suite =
    describe "Qualifier"
        [ test "Simple program" <|
            \_ ->
................................................................................
                                    , Type.Custom "False"
                                    ]
                                , AST.CustomTypeDef emptyRange "True" [] []
                                , AST.CustomTypeDef emptyRange "False" [] []
                                ]
                        , words =
                            Dict.fromListBy .name


















                                [ { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange (Type.Custom "False") [], [ AST.Integer emptyRange 0 ] )
                                            , ( AST.TypeMatch emptyRange (Type.Custom "True") [], [ AST.Integer emptyRange 1 ] )
                                            ]
                                            []
                                  }
                                ]
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    emptyRange
                                    []
................................................................................
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef "True" emptyRange [] []
                                , CustomTypeDef "False" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name


















                                [ { name = "to-int"
                                  , metadata = Metadata.default
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (Type.Custom "False") [], [ Integer emptyRange 0 ] )
                                            , ( TypeMatch emptyRange (Type.Custom "True") [], [ Integer emptyRange 1 ] )
                                            ]
                                            []
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
................................................................................
                                    , AST.CustomTypeDef emptyRange
                                        "Box"
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name













































                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Custom "Box") [ ( "value", AST.LiteralInt 0 ) ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
                                Dict.fromListBy typeDefinitionName
                                    [ UnionTypeDef "Bool"
                                        emptyRange
                                        []
................................................................................
                                    , CustomTypeDef "Box"
                                        emptyRange
                                        []
                                        [ ( "value", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name













































                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "Box") [ ( "value", LiteralInt 0 ) ], [ Word emptyRange ">True" ] )
                                                ]
                                                [ Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run unqualifiedAst of
                        Err _ ->
                            Expect.fail "Did not expect qualification to fail"

                        Ok qualifiedAst ->
                            Expect.equal expectedAst qualifiedAst
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
                                    , AST.CustomTypeDef emptyRange "Nothing" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name









                                    [ { name = "with-default"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "swap"
                                                , AST.Word emptyRange "drop"
                                                ]
                                      }
                                    ]
                            }
                                |> 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
                                                [ ( TypeMatch emptyRange (Type.Generic "a") []
                                                  , [ Builtin emptyRange Builtin.StackDrop ]
                                                  )
                                                ]
                                                [ Builtin emptyRange Builtin.StackSwap
                                                , Builtin emptyRange Builtin.StackDrop
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run unqualifiedAst of
                        Err _ ->
                            Expect.fail "Did not expect qualification to fail"

                        Ok qualifiedAst ->
                            Expect.equal expectedAst qualifiedAst
................................................................................
                                , AST.CustomTypeDef emptyRange
                                    "Box"
                                    []
                                    [ ( "value", Type.Custom "Bool" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name















































                                [ { name = "true?"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ Type.Custom "Bool" ]
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange
                                                    (Type.Custom "Box")
................................................................................
                                              , [ AST.Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ AST.Word emptyRange ">False" ]
                                  }
                                ]
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
                            Dict.fromListBy typeDefinitionName
                                [ UnionTypeDef "Bool"
                                    emptyRange
                                    []
................................................................................
                                , CustomTypeDef "Box"
                                    emptyRange
                                    []
                                    [ ( "value", boolUnion ) ]
                                ]
                        , words =
                            Dict.fromListBy .name













































                                [ { name = "true?"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ boolUnion ]
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange
                                                    (Type.Custom "Box")
................................................................................
                                              , [ Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ Word emptyRange ">False" ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
        ]

Added tests/Test/Qualifier/Util.elm version [e107564c2e].























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module Test.Qualifier.Util exposing (addFunctionsForStructs)

import Dict
import Dict.Extra as Dict
import Play.Data.Metadata as Metadata
import Play.Data.Type as Type exposing (Type)
import Play.Qualifier as AST exposing (AST)


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


addFunctionsForStructsHelper : String -> List String -> List ( String, Type ) -> AST -> AST
addFunctionsForStructsHelper name generics members ast =
    let
        selfType =
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =
            { name = ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =
            List.map settersHelper members

        settersHelper ( memberName, type_ ) =
            { name = ">" ++ memberName
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType
                        [ selfType, type_ ]
                        [ selfType ]
            , implementation =
                AST.SoloImpl [ AST.SetMember name memberName ]
            }

        getters =
            List.map gettersHelper members

        gettersHelper ( memberName, type_ ) =
            { name = memberName ++ ">"
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType
                        [ selfType ]
                        [ type_ ]
            , implementation =
                AST.SoloImpl [ AST.GetMember name memberName ]
            }

        allFuncs =
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }

Modified tests/Test/TypeChecker.elm from [5ce2f71b87] to [ccb93b6437].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
164
165
166
167
168
169
170

171
172
173
174
175
176
177
...
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
212
213
214
215
216
217
218
219
...
231
232
233
234
235
236
237

238
239
240
241
242
243
244
...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
...
610
611
612
613
614
615
616

617
618
619
620
621
622
623
...
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
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
813
814
815
816
...
855
856
857
858
859
860
861

862
863
864
865
866
867
868
...
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
...
937
938
939
940
941
942
943

944
945
946
947
948
949
950
...
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
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
....
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
....
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
....
1145
1146
1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
....
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
....
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
....
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
....
1510
1511
1512
1513
1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
....
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
....
1662
1663
1664
1665
1666
1667
1668

1669
1670
1671
1672
1673
1674
1675
module Test.TypeChecker exposing (..)

import Dict
import Dict.Extra as Dict
import Expect
import Play.Data.Builtin as Builtin
import Play.Data.Metadata as Metadata exposing (Metadata)
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type
import Play.Qualifier as QAST
import Play.TypeChecker exposing (..)
import Play.TypeChecker.Problem as Problem
import Test exposing (Test, describe, test)



suite : Test
suite =
    describe "TypeChecker"
        [ test "Simple program" <|
            \_ ->
................................................................................
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "True" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Custom "True" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "True" ]
                                  }
                                , { name = "as-int"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Integer emptyRange 1
                                            ]
................................................................................
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange ">True"
                                            , QAST.Word emptyRange "as-int"
                                            ]
                                  }
                                ]
                        }

                in
                case run source of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail"

                    Ok _ ->
                        Expect.pass
................................................................................
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Person" emptyRange [] [ ( "age", Type.Int ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">Person"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Int ] [ Type.Custom "Person" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "Person" ]
                                  }
                                , { name = ">age"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Person", Type.Int ] [ Type.Custom "Person" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.SetMember "Person" "age" ]
                                  }
                                , { name = "age>"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Person" ] [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.GetMember "Person" "age" ]
                                  }
                                , { name = "inc-age"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Person" ] [ Type.Custom "Person" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "age>"
                                            , QAST.Integer emptyRange 1
................................................................................
                                            , QAST.Word emptyRange ">Person"
                                            , QAST.Word emptyRange "inc-age"
                                            , QAST.Word emptyRange "age>"
                                            ]
                                  }
                                ]
                        }

                in
                case run source of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail"

                    Ok _ ->
                        Expect.pass
................................................................................
                                            , QAST.Word emptyRange "element>"
                                            , QAST.Integer emptyRange 10
                                            , QAST.Builtin emptyRange Builtin.Plus
                                            , QAST.Integer emptyRange 15
                                            , QAST.Builtin emptyRange Builtin.Equal
                                            ]
                                  }
                                , { name = ">Box"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Generic "a" ] [ Type.CustomGeneric "Box" [ Type.Generic "a" ] ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "Box"
                                            ]
                                  }
                                , { name = ">element"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.CustomGeneric "Box" [ Type.Generic "a" ], Type.Generic "a" ]
                                                [ Type.CustomGeneric "Box" [ Type.Generic "a" ] ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.SetMember "Box" "element" ]
                                  }
                                , { name = "element>"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.CustomGeneric "Box" [ Type.Generic "a" ] ]
                                                [ Type.Generic "a" ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.GetMember "Box" "element" ]
                                  }
                                ]
                        }

                in
                case run input of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail."

                    Ok _ ->
                        Expect.pass
................................................................................
                                            , QAST.Builtin emptyRange Builtin.StackDuplicate
                                            , QAST.Word emptyRange "x>"
                                            , QAST.Builtin emptyRange Builtin.StackLeftRotate
                                            , QAST.Builtin emptyRange Builtin.Apply
                                            , QAST.Word emptyRange ">x"
                                            ]
                                  }
                                , { name = ">Coordinate"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Int, Type.Int ] [ Type.Custom "Coordinate" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "Coordinate"
                                            ]
                                  }
                                , { name = ">x"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Custom "Coordinate", Type.Int ]
                                                [ Type.Custom "Coordinate" ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.SetMember "Coordinate" "x" ]
                                  }
                                , { name = "x>"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Custom "Coordinate" ]
                                                [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.GetMember "Coordinate" "x" ]
                                  }
                                , { name = ">y"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Custom "Coordinate", Type.Int ]
                                                [ Type.Custom "Coordinate" ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.SetMember "Coordinate" "y" ]
                                  }
                                , { name = "y>"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Custom "Coordinate" ]
                                                [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl [ QAST.GetMember "Coordinate" "y" ]
                                  }
                                ]
                        }

                in
                case run input of
                    Err err ->
                        err
                            |> List.map (Problem.toString "")
                            |> String.join "\n"
                            |> (++) "Did not expect type check to fail.\n"
................................................................................
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box" emptyRange [] [ ( "element", Type.Generic "a" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">Box"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Generic "a" ] [ Type.Custom "Box" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "Box"
                                            ]
                                  }
                                ]
                        }

                in
                case run input of
                    Ok _ ->
                        Expect.fail "Expected type check to fail."

                    Err _ ->
                        Expect.pass
................................................................................
                let
                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Box" emptyRange [ "a" ] [ ( "element", Type.Generic "b" ) ]
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">Box"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Generic "b" ] [ Type.Custom "Box" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.ConstructType "Box"
                                            ]
                                  }
                                ]
                        }

                in
                case run input of
                    Ok _ ->
                        Expect.fail "Expected type check to fail."

                    Err _ ->
                        Expect.pass
................................................................................
                                , Type.Custom "False"
                                ]
                            , QAST.CustomTypeDef "True" emptyRange [] []
                            , QAST.CustomTypeDef "False" emptyRange [] []
                            ]
                    , words =
                        Dict.fromListBy .name
                            [ { name = ">True"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.withType [] [ Type.Custom "True" ]
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.ConstructType "True"
                                        ]
                              }
                            , { name = ">False"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.withType [] [ Type.Custom "False" ]
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.ConstructType "False"
                                        ]
                              }
                            , multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.asEntryPoint
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.Word emptyRange ">True"
................................................................................
                                        , QAST.Word emptyRange ">False"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Builtin emptyRange Builtin.Equal
                                        ]
                              }
                            ]
                    }

            in
            [ test "Simplest case" <|
                \_ ->
                    let
                        input =
                            template
                                { name = "to-int"
................................................................................
                                    , QAST.CustomTypeDef "Dog"
                                        emptyRange
                                        []
                                        [ ( "man-years", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Person"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int ] [ Type.Custom "Person" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "Person"
                                                ]
                                      }
                                    , { name = ">Dog"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Int ] [ Type.Custom "Dog" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "Dog"
                                                ]
                                      }
                                    , { name = "age>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Person" ] [ Type.Int ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "Person" "age"
                                                ]
                                      }
                                    , { name = "man-years>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Dog" ] [ Type.Int ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "Dog" "man-years"
                                                ]
                                      }
                                    , { name = ">age"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Person", Type.Int ] [ Type.Custom "Person" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "Person" "age"
                                                ]
                                      }
                                    , { name = ">man-years"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Dog", Type.Int ] [ Type.Custom "Dog" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "Dog" "man-years"
                                                ]
                                      }
                                    , { name = "add-to-age"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "Person") []
                                                  , [ QAST.Word emptyRange ">age"
                                                    ]
                                                  )
................................................................................
                                                , QAST.Word emptyRange "get-man-age"
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.Builtin emptyRange Builtin.Minus
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Err _ ->
                            Expect.fail "Did not expect type check to fail."

                        Ok _ ->
                            Expect.pass
................................................................................
                                        , Type.Custom "False"
                                        ]
                                    , QAST.CustomTypeDef "True" emptyRange [] []
                                    , QAST.CustomTypeDef "False" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">True"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "True" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "True"
                                                ]
                                      }
                                    , { name = ">False"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "False" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "False"
                                                ]
                                      }
                                    , { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange ">False"
                                                    ]
................................................................................
                                                [ QAST.Word emptyRange ">True"
                                                , QAST.Word emptyRange "not"
                                                , QAST.Word emptyRange "true-to-int"
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Ok _ ->
                            Expect.fail "Did not expect type check to pass."

                        Err _ ->
                            Expect.pass
................................................................................
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">EmptyList"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "EmptyList" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "EmptyList"
                                                ]
                                      }
                                    , { name = ">NonEmptyList"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Generic "a", listUnion ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "NonEmptyList"
                                                ]
                                      }
                                    , { name = "first>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "NonEmptyList" "first"
                                                ]
                                      }
                                    , { name = ">first"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ], Type.Generic "a" ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "NonEmptyList" "first"
                                                ]
                                      }
                                    , { name = "rest>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                                    [ listUnion ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "NonEmptyList" "rest"
                                                ]
                                      }
                                    , { name = ">rest"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ], listUnion ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "NonEmptyList" "rest"
                                                ]
                                      }
                                    , { name = "first-or-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ listUnion, Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                                , QAST.Word emptyRange "first-or-default"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Equal
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err _ ->
                            Expect.fail "Expected type check to pass."
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "with-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ maybeUnion, Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                                [ QAST.Word emptyRange ">Nil"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange "with-default"
                                                ]
                                      }
                                    ]
                            }


                        expectedResult =
                            { types =
                                Dict.fromListBy typeDefName
                                    [ UnionTypeDef "Maybe"
                                        emptyRange
                                        [ "a" ]
................................................................................
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , type_ = { input = [], output = [ Type.Custom "Nil" ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "with-default"
                                      , type_ =
................................................................................
                                        [ "a" ]
                                        [ Type.Generic "b"
                                        , Type.Custom "Nothing"
                                        ]
                                    , QAST.CustomTypeDef "Nothing" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nothing"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nothing" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "Nothing"
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Ok _ ->
                            Expect.fail "Expected type check to fail."

                        Err _ ->
                            Expect.pass
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "map"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ maybeUnion "a"
                                                    , Type.Quotation
                                                        { input = [ Type.Generic "a" ]
                                                        , output = [ Type.Generic "b" ]
................................................................................
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Minus
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err err ->
                            Expect.fail <| "Did not expect type check to fail: " ++ Debug.toString err
................................................................................
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">EmptyList"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [] [ Type.Custom "EmptyList" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "EmptyList"
                                                ]
                                      }
                                    , { name = ">NonEmptyList"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Generic "a", listUnion ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.ConstructType "NonEmptyList"
                                                ]
                                      }
                                    , { name = "first>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "NonEmptyList" "first"
                                                ]
                                      }
                                    , { name = ">first"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ], Type.Generic "a" ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "NonEmptyList" "first"
                                                ]
                                      }
                                    , { name = "rest>"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                                    [ listUnion ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.GetMember "NonEmptyList" "rest"
                                                ]
                                      }
                                    , { name = ">rest"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ], listUnion ]
                                                    [ Type.CustomGeneric "NonEmptyList" [ Type.Generic "a" ] ]
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.SetMember "NonEmptyList" "rest"
                                                ]
                                      }
                                    , { name = "sum"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 0
                                                , QAST.Word emptyRange "sum-helper"
                                                ]
                                      }
................................................................................
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange "sum"
                                                ]
                                      }
                                    ]
                            }

                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err _ ->
                            Expect.fail "Did not expect type check to fail."






|






>







 







<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>







 







<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>







 







|
<
<
<
<
<
<
<
<
|
<
<
>







 







|
<
<
<
<
<
<
<
<
|
<
<
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
|







 







>







 







|







 







|
<
<
<
<
<
<
<
<
|
<
<
>







 







<
<
<
<
<
<
<
<
<
|







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
136
137
138
139
140
141
142








143
144
145
146
147
148
149
150
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
175
176
177
178
179
180
181
























182
183
184
185
186
187
188
189
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
320
321
322
323
324
325
326







327
328




















329
330
331
332
333
334
335
336
...
385
386
387
388
389
390
391







392
393






































394
395
396
397
398
399
400
401
...
408
409
410
411
412
413
414
415








416


417
418
419
420
421
422
423
424
...
427
428
429
430
431
432
433
434








435


436
437
438
439
440
441
442
443
...
459
460
461
462
463
464
465


















466
467
468
469
470
471
472
473
...
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
...
614
615
616
617
618
619
620






















































621
622
623
624
625
626
627
628
...
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
...
692
693
694
695
696
697
698


















699
700
701
702
703
704
705
706
...
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
...
768
769
770
771
772
773
774
































































775
776
777
778
779
780
781
782
...
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
...
836
837
838
839
840
841
842









843
844
845
846
847
848
849
850
...
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
...
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
...
962
963
964
965
966
967
968
969








970


971
972
973
974
975
976
977
978
....
1170
1171
1172
1173
1174
1175
1176









1177
1178
1179
1180
1181
1182
1183
1184
....
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
....
1255
1256
1257
1258
1259
1260
1261
































































1262
1263
1264
1265
1266
1267
1268
1269
....
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
module Test.TypeChecker exposing (..)

import Dict
import Dict.Extra as Dict
import Expect
import Play.Data.Builtin as Builtin
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type
import Play.Qualifier as QAST
import Play.TypeChecker exposing (..)
import Play.TypeChecker.Problem as Problem
import Test exposing (Test, describe, test)
import Test.Qualifier.Util as QualifierUtil


suite : Test
suite =
    describe "TypeChecker"
        [ test "Simple program" <|
            \_ ->
................................................................................
                    source =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "True" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name








                                [ { name = "as-int"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Integer emptyRange 1
                                            ]
................................................................................
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange ">True"
                                            , QAST.Word emptyRange "as-int"
                                            ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run source of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail"

                    Ok _ ->
                        Expect.pass
................................................................................
                    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" ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "age>"
                                            , QAST.Integer emptyRange 1
................................................................................
                                            , QAST.Word emptyRange ">Person"
                                            , QAST.Word emptyRange "inc-age"
                                            , QAST.Word emptyRange "age>"
                                            ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run source of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail"

                    Ok _ ->
                        Expect.pass
................................................................................
                                            , QAST.Word emptyRange "element>"
                                            , QAST.Integer emptyRange 10
                                            , QAST.Builtin emptyRange Builtin.Plus
                                            , QAST.Integer emptyRange 15
                                            , QAST.Builtin emptyRange Builtin.Equal
                                            ]
                                  }







                                ]
                        }




















                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
                    Err _ ->
                        Expect.fail "Did not expect type check to fail."

                    Ok _ ->
                        Expect.pass
................................................................................
                                            , QAST.Builtin emptyRange Builtin.StackDuplicate
                                            , QAST.Word emptyRange "x>"
                                            , QAST.Builtin emptyRange Builtin.StackLeftRotate
                                            , QAST.Builtin emptyRange Builtin.Apply
                                            , QAST.Word emptyRange ">x"
                                            ]
                                  }







                                ]
                        }






































                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
                    Err err ->
                        err
                            |> List.map (Problem.toString "")
                            |> String.join "\n"
                            |> (++) "Did not expect type check to fail.\n"
................................................................................
                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
                    Ok _ ->
                        Expect.fail "Expected type check to fail."

                    Err _ ->
                        Expect.pass
................................................................................
                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
                    Ok _ ->
                        Expect.fail "Expected type check to fail."

                    Err _ ->
                        Expect.pass
................................................................................
                                , Type.Custom "False"
                                ]
                            , QAST.CustomTypeDef "True" emptyRange [] []
                            , QAST.CustomTypeDef "False" emptyRange [] []
                            ]
                    , words =
                        Dict.fromListBy .name


















                            [ multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.asEntryPoint
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.Word emptyRange ">True"
................................................................................
                                        , QAST.Word emptyRange ">False"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Builtin emptyRange Builtin.Equal
                                        ]
                              }
                            ]
                    }
                        |> QualifierUtil.addFunctionsForStructs
            in
            [ test "Simplest case" <|
                \_ ->
                    let
                        input =
                            template
                                { name = "to-int"
................................................................................
                                    , QAST.CustomTypeDef "Dog"
                                        emptyRange
                                        []
                                        [ ( "man-years", Type.Int ) ]
                                    ]
                            , words =
                                Dict.fromListBy .name






















































                                    [ { name = "add-to-age"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "Person") []
                                                  , [ QAST.Word emptyRange ">age"
                                                    ]
                                                  )
................................................................................
                                                , QAST.Word emptyRange "get-man-age"
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.Builtin emptyRange Builtin.Minus
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Err _ ->
                            Expect.fail "Did not expect type check to fail."

                        Ok _ ->
                            Expect.pass
................................................................................
                                        , Type.Custom "False"
                                        ]
                                    , QAST.CustomTypeDef "True" emptyRange [] []
                                    , QAST.CustomTypeDef "False" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name


















                                    [ { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange ">False"
                                                    ]
................................................................................
                                                [ QAST.Word emptyRange ">True"
                                                , QAST.Word emptyRange "not"
                                                , QAST.Word emptyRange "true-to-int"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Ok _ ->
                            Expect.fail "Did not expect type check to pass."

                        Err _ ->
                            Expect.pass
................................................................................
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
































































                                    [ { name = "first-or-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ listUnion, Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                                , QAST.Word emptyRange "first-or-default"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Equal
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err _ ->
                            Expect.fail "Expected type check to pass."
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name









                                    [ { name = "with-default"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ maybeUnion, Type.Generic "a" ]
                                                    [ Type.Generic "a" ]
                                      , implementation =
                                            QAST.MultiImpl
................................................................................
                                                [ QAST.Word emptyRange ">Nil"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange "with-default"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs

                        expectedResult =
                            { types =
                                Dict.fromListBy typeDefName
                                    [ UnionTypeDef "Maybe"
                                        emptyRange
                                        [ "a" ]
................................................................................
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , type_ = { input = [], output = [ Type.Custom "Nil" ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Nil"
                                                ]
                                      }
                                    , { name = "with-default"
                                      , type_ =
................................................................................
                                        [ "a" ]
                                        [ Type.Generic "b"
                                        , Type.Custom "Nothing"
                                        ]
                                    , QAST.CustomTypeDef "Nothing" emptyRange [] []
                                    ]
                            , words =
                                Dict.empty








                            }


                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Ok _ ->
                            Expect.fail "Expected type check to fail."

                        Err _ ->
                            Expect.pass
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , QAST.CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name









                                    [ { name = "map"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ maybeUnion "a"
                                                    , Type.Quotation
                                                        { input = [ Type.Generic "a" ]
                                                        , output = [ Type.Generic "b" ]
................................................................................
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Minus
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err err ->
                            Expect.fail <| "Did not expect type check to fail: " ++ Debug.toString err
................................................................................
                                        [ ( "first", Type.Generic "a" )
                                        , ( "rest", listUnion )
                                        ]
                                    , QAST.CustomTypeDef "EmptyList" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
































































                                    [ { name = "sum"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 0
                                                , QAST.Word emptyRange "sum-helper"
                                                ]
                                      }
................................................................................
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange "sum"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run input of
                        Ok _ ->
                            Expect.pass

                        Err _ ->
                            Expect.fail "Did not expect type check to fail."