Stabel

Check-in [cd6f72e996]
Login
Overview
Comment:Qualifier now fully understands aliasing of types.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: cd6f72e9966ae86b29d01bed1a0aeac21f1cb7bf2186527e37926da3dc440aa0
User & Date: robin.hansen on 2021-05-25 17:30:53
Other Links: branch diff | manifest | tags
Context
2021-05-25
19:37
Qualifier nearly understands imports, now. A failing test marks what remains of work. check-in: d888dffff5 user: robin.hansen tags: module-definition
17:30
Qualifier now fully understands aliasing of types. check-in: cd6f72e996 user: robin.hansen tags: module-definition
2021-05-24
15:12
Qualifier can qualify type references to external packages. check-in: 3b205d8501 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Qualifier.elm from [54893189da] to [1ea017ec95].

165
166
167
168
169
170
171









172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
218
219
220
221
222
223
224


225
226
227
228



























229
230
231
232
233
234
235
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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
...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
...
373
374
375
376
377
378
379
380









381
382
383
384
385
386
387
...
437
438
439
440
441
442
443










444
445
446
447
448
449
450
451
452
453
454
455
...
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
...
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
...
604
605
606
607
608
609
610

































611
612
613
614
615
616
617
...
634
635
636
637
638
639
640


641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
...
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931

qualifyType :
    RunConfig
    -> Parser.TypeDefinition
    -> ( List Problem, Dict String TypeDefinition )
    -> ( List Problem, Dict String TypeDefinition )
qualifyType config typeDef ( errors, acc ) =









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

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

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

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

                qualifiedMemberTypesResult =
                    List.map (qualifyMemberType config range) memberTypes
                        |> Result.combine
            in
            case qualifiedMemberTypesResult of
                Err err ->
                    ( err :: errors
                    , acc
                    )
................................................................................
                    ( errors
                    , Dict.insert qualifiedName (UnionTypeDef qualifiedName range generics qualifiedMemberTypes) acc
                    )


qualifyMemberType :
    RunConfig


    -> SourceLocationRange
    -> Parser.PossiblyQualifiedType
    -> Result Problem Type
qualifyMemberType config range type_ =



























    case type_ of
        Parser.LocalRef "Int" [] ->
            Ok <| Type.Int

        Parser.LocalRef name [] ->
            case Dict.get name config.ast.types of
                Just _ ->
................................................................................

        Parser.LocalRef name binds ->
            case Dict.get name config.ast.types of
                Just _ ->
                    let
                        bindResult =
                            binds
                                |> List.map (qualifyMemberType config range)
                                |> Result.combine
                    in
                    case bindResult of
                        Ok convertedBindings ->
                            Ok <|
                                Type.CustomGeneric
                                    (qualifyName config name)
................................................................................

                        Err err ->
                            Err err

                Nothing ->
                    Err <| UnknownTypeRef range name

        Parser.InternalRef path name binds ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
                        |> qualifyPackageModule config.packageName

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

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

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

                _ ->
                    Err <| UnknownTypeRef range qualifiedName

        Parser.ExternalRef path name binds ->
            let
                pathString =
                    "/" ++ String.join "/" path

                qualifiedName =
                    Dict.get pathString config.externalModules
                        |> Maybe.map (\prefix -> "/" ++ prefix ++ pathString ++ "/" ++ name)
                        |> Maybe.withDefault ""

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

                ( Just (CustomTypeDef _ _ _ _), Ok qualifiedBinds ) ->
................................................................................
        Parser.StackRange sym ->
            Ok (Type.Generic sym)

        Parser.QuotationType sign ->
            let
                inputResult =
                    sign.input
                        |> List.map (qualifyMemberType config range)
                        |> Result.combine

                outputResult =
                    sign.output
                        |> List.map (qualifyMemberType config range)
                        |> Result.combine
            in
            case ( inputResult, outputResult ) of
                ( Ok input, Ok output ) ->
                    Ok <|
                        Type.Quotation
                            { input = input
................................................................................
                Parser.Undefined ->
                    { aliases = unqualifiedWord.aliases
                    , imports = unqualifiedWord.imports
                    }

        ( newWordsAfterWhens, qualifiedWhensResult ) =
            whens
                |> List.foldr (qualifyWhen config qualifiedTypes unqualifiedWord.name moduleReferences) ( acc, [] )









                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
            initQualifyNode config unqualifiedWord.name moduleReferences newWordsAfterWhens impl

        qualifiedMetadataResult =
            qualifyMetadata config qualifiedTypes unqualifiedWord
................................................................................
                    0

                Parser.UserProvided wt ->
                    List.length wt.input

                Parser.Verified wt ->
                    List.length wt.input










    in
    Parser.typeSignatureToMaybe word.typeSignature
        |> Maybe.map (\ts -> ts.input ++ ts.output)
        |> Maybe.withDefault []
        |> List.map (qualifyMemberType config wordRange)
        |> Result.combine
        |> Result.map
            (\qualifiedFlatTypeSignature ->
                let
                    wordType =
                        { input = List.take inputLength qualifiedFlatTypeSignature
                        , output = List.drop inputLength qualifiedFlatTypeSignature
................................................................................
    , output = List.map (resolveUnion typeDefs) wt.output
    }


qualifyWhen :
    RunConfig
    -> Dict String TypeDefinition


    -> String
    -> ModuleReferences
    -> ( Parser.TypeMatch, List Parser.AstNode )
    -> ( Dict String WordDefinition, List (Result Problem ( TypeMatch, List Node )) )
    -> ( Dict String WordDefinition, List (Result Problem ( TypeMatch, List Node )) )
qualifyWhen config qualifiedTypes wordName modRefs ( typeMatch, impl ) ( qualifiedWords, result ) =
    let
        ( newWords, qualifiedImplementationResult ) =
            initQualifyNode config wordName modRefs qualifiedWords impl

        qualifiedMatchResult =
            qualifyMatch config qualifiedTypes typeMatch
    in
    case ( qualifiedImplementationResult, qualifiedMatchResult ) of
        ( Err err, _ ) ->
            ( newWords
            , Err err :: result
            )

................................................................................

        ( Ok qualifiedImplementation, Ok qualifiedMatch ) ->
            ( newWords
            , Ok ( qualifiedMatch, qualifiedImplementation ) :: result
            )




qualifyMatch : RunConfig -> Dict String TypeDefinition -> Parser.TypeMatch -> Result Problem TypeMatch




qualifyMatch config qualifiedTypes typeMatch =
    let
        qualifiedNameToMatch range name patterns =
            case Dict.get name qualifiedTypes of
                Just (CustomTypeDef _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
                            patterns

                                |> List.map (qualifyMatchValue config qualifiedTypes range name memberNames)








                                |> Result.combine

                        actualType =
                            case gens of
                                [] ->
                                    Type.Custom name

................................................................................
            Ok <| TypeMatch range Type.Int [ ( "value", LiteralInt val ) ]

        Parser.TypeMatch range (Parser.Generic sym) [] ->
            Ok <| TypeMatch range (Type.Generic sym) []

        Parser.TypeMatch range (Parser.LocalRef name []) patterns ->
            qualifiedNameToMatch range (qualifyName config name) patterns


































        Parser.TypeMatch range (Parser.InternalRef path name _) patterns ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
................................................................................
        Parser.TypeMatch range _ _ ->
            Err <| InvalidTypeMatch range


qualifyMatchValue :
    RunConfig
    -> Dict String TypeDefinition


    -> SourceLocationRange
    -> String
    -> Set String
    -> ( String, Parser.TypeMatchValue )
    -> Result Problem ( String, TypeMatchValue )
qualifyMatchValue config qualifiedTypes range typeName memberNames ( fieldName, matchValue ) =
    if Set.member fieldName memberNames then
        case matchValue of
            Parser.LiteralInt val ->
                Ok <| ( fieldName, LiteralInt val )

            Parser.LiteralType type_ ->
                let
                    qualifyTypeResult =
                        qualifyMemberType config range type_
                in
                case qualifyTypeResult of
                    Ok qualifiedType ->
                        Ok <| ( fieldName, LiteralType qualifiedType )

                    Err err ->
                        Err err

            Parser.RecursiveMatch typeMatch ->
                case qualifyMatch config qualifiedTypes typeMatch of
                    Err err ->
                        Err err

                    Ok match ->
                        Ok <| ( fieldName, RecursiveMatch match )

    else
................................................................................
            modRefs.imports
                |> Dict.toList
                |> List.find (\( _, v ) -> List.member name v)
                |> Maybe.map Tuple.first

        potentialCandidates =
            modRefs.imports
                |> Dict.filter (\k v -> List.isEmpty v)
                |> Dict.keys
                |> List.filterMap resolveMod
                |> List.map (\mod -> ( mod, mod ++ "/" ++ name ))

        resolveMod mod =
            if String.startsWith "/" mod then
                Dict.get mod config.externalModules







>
>
>
>
>
>
>
>
>







|







 







|







 







>
>



|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







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













|







 







|




|







 







|
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>




|







 







>
>





|





|







 







>
>
|
>
>
>
>
|












>
|
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>





|








|









|







 







|







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
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321




322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
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
...
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
...
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
...
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
...
737
738
739
740
741
742
743
744
745
746
747
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
....
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036

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

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

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

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

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

                qualifiedMemberTypesResult =
                    List.map (qualifyMemberType config aliases imports range) memberTypes
                        |> Result.combine
            in
            case qualifiedMemberTypesResult of
                Err err ->
                    ( err :: errors
                    , acc
                    )
................................................................................
                    ( errors
                    , Dict.insert qualifiedName (UnionTypeDef qualifiedName range generics qualifiedMemberTypes) acc
                    )


qualifyMemberType :
    RunConfig
    -> Dict String String
    -> Dict String (List String)
    -> SourceLocationRange
    -> Parser.PossiblyQualifiedType
    -> Result Problem Type
qualifyMemberType config aliases imports range type_ =
    let
        internalRefLookup path name binds =
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
                        |> qualifyPackageModule config.packageName

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

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

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

                _ ->
                    Err <| UnknownTypeRef range qualifiedName
    in
    case type_ of
        Parser.LocalRef "Int" [] ->
            Ok <| Type.Int

        Parser.LocalRef name [] ->
            case Dict.get name config.ast.types of
                Just _ ->
................................................................................

        Parser.LocalRef name binds ->
            case Dict.get name config.ast.types of
                Just _ ->
                    let
                        bindResult =
                            binds
                                |> List.map (qualifyMemberType config aliases imports range)
                                |> Result.combine
                    in
                    case bindResult of
                        Ok convertedBindings ->
                            Ok <|
                                Type.CustomGeneric
                                    (qualifyName config name)
................................................................................

                        Err err ->
                            Err err

                Nothing ->
                    Err <| UnknownTypeRef range name

        Parser.InternalRef ([ possibleAlias ] as path) name binds ->
            case Dict.get possibleAlias aliases of
                Just val ->
                    if String.startsWith "/" val then
                        let
                            newPath =
                                val
                                    |> String.split "/"
                                    |> List.drop 1
                        in
                        qualifyMemberType config aliases imports range <|
                            Parser.ExternalRef newPath name binds

                    else
                        internalRefLookup (String.split "/" val) name binds

                Nothing ->
                    internalRefLookup path name binds

        Parser.InternalRef path name binds ->
            internalRefLookup path name binds





        Parser.ExternalRef path name binds ->
            let
                pathString =
                    "/" ++ String.join "/" path

                qualifiedName =
                    Dict.get pathString config.externalModules
                        |> Maybe.map (\prefix -> "/" ++ prefix ++ pathString ++ "/" ++ name)
                        |> Maybe.withDefault ""

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

                ( Just (CustomTypeDef _ _ _ _), Ok qualifiedBinds ) ->
................................................................................
        Parser.StackRange sym ->
            Ok (Type.Generic sym)

        Parser.QuotationType sign ->
            let
                inputResult =
                    sign.input
                        |> List.map (qualifyMemberType config aliases imports range)
                        |> Result.combine

                outputResult =
                    sign.output
                        |> List.map (qualifyMemberType config aliases imports range)
                        |> Result.combine
            in
            case ( inputResult, outputResult ) of
                ( Ok input, Ok output ) ->
                    Ok <|
                        Type.Quotation
                            { input = input
................................................................................
                Parser.Undefined ->
                    { aliases = unqualifiedWord.aliases
                    , imports = unqualifiedWord.imports
                    }

        ( newWordsAfterWhens, qualifiedWhensResult ) =
            whens
                |> List.foldr
                    (qualifyWhen
                        config
                        qualifiedTypes
                        moduleReferences.aliases
                        moduleReferences.imports
                        unqualifiedWord.name
                        moduleReferences
                    )
                    ( acc, [] )
                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
            initQualifyNode config unqualifiedWord.name moduleReferences newWordsAfterWhens impl

        qualifiedMetadataResult =
            qualifyMetadata config qualifiedTypes unqualifiedWord
................................................................................
                    0

                Parser.UserProvided wt ->
                    List.length wt.input

                Parser.Verified wt ->
                    List.length wt.input

        ( aliases, imports ) =
            case config.ast.moduleDefinition of
                Parser.Undefined ->
                    ( word.aliases, word.imports )

                Parser.Defined mod ->
                    ( Dict.union mod.aliases word.aliases
                    , Dict.union mod.imports word.imports
                    )
    in
    Parser.typeSignatureToMaybe word.typeSignature
        |> Maybe.map (\ts -> ts.input ++ ts.output)
        |> Maybe.withDefault []
        |> List.map (qualifyMemberType config aliases imports wordRange)
        |> Result.combine
        |> Result.map
            (\qualifiedFlatTypeSignature ->
                let
                    wordType =
                        { input = List.take inputLength qualifiedFlatTypeSignature
                        , output = List.drop inputLength qualifiedFlatTypeSignature
................................................................................
    , output = List.map (resolveUnion typeDefs) wt.output
    }


qualifyWhen :
    RunConfig
    -> Dict String TypeDefinition
    -> Dict String String
    -> Dict String (List String)
    -> String
    -> ModuleReferences
    -> ( Parser.TypeMatch, List Parser.AstNode )
    -> ( Dict String WordDefinition, List (Result Problem ( TypeMatch, List Node )) )
    -> ( Dict String WordDefinition, List (Result Problem ( TypeMatch, List Node )) )
qualifyWhen config qualifiedTypes aliases imports wordName modRefs ( typeMatch, impl ) ( qualifiedWords, result ) =
    let
        ( newWords, qualifiedImplementationResult ) =
            initQualifyNode config wordName modRefs qualifiedWords impl

        qualifiedMatchResult =
            qualifyMatch config qualifiedTypes aliases imports typeMatch
    in
    case ( qualifiedImplementationResult, qualifiedMatchResult ) of
        ( Err err, _ ) ->
            ( newWords
            , Err err :: result
            )

................................................................................

        ( Ok qualifiedImplementation, Ok qualifiedMatch ) ->
            ( newWords
            , Ok ( qualifiedMatch, qualifiedImplementation ) :: result
            )


qualifyMatch :
    RunConfig
    -> Dict String TypeDefinition
    -> Dict String String
    -> Dict String (List String)
    -> Parser.TypeMatch
    -> Result Problem TypeMatch
qualifyMatch config qualifiedTypes aliases imports typeMatch =
    let
        qualifiedNameToMatch range name patterns =
            case Dict.get name qualifiedTypes of
                Just (CustomTypeDef _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
                            patterns
                                |> List.map
                                    (qualifyMatchValue
                                        config
                                        qualifiedTypes
                                        aliases
                                        imports
                                        range
                                        name
                                        memberNames
                                    )
                                |> Result.combine

                        actualType =
                            case gens of
                                [] ->
                                    Type.Custom name

................................................................................
            Ok <| TypeMatch range Type.Int [ ( "value", LiteralInt val ) ]

        Parser.TypeMatch range (Parser.Generic sym) [] ->
            Ok <| TypeMatch range (Type.Generic sym) []

        Parser.TypeMatch range (Parser.LocalRef name []) patterns ->
            qualifiedNameToMatch range (qualifyName config name) patterns

        Parser.TypeMatch range (Parser.InternalRef [ possibleAlias ] name _) patterns ->
            case Dict.get possibleAlias aliases of
                Just actualPath ->
                    if String.startsWith "/" actualPath then
                        let
                            extPath =
                                actualPath
                                    |> String.dropLeft 1
                                    |> String.split "/"
                        in
                        qualifyMatch config qualifiedTypes aliases imports <|
                            Parser.TypeMatch range (Parser.ExternalRef extPath name []) patterns

                    else
                        let
                            qualifiedName =
                                actualPath
                                    ++ "/"
                                    ++ name
                                    |> qualifyPackageModule config.packageName
                        in
                        qualifiedNameToMatch range qualifiedName patterns

                Nothing ->
                    let
                        qualifiedName =
                            possibleAlias
                                ++ "/"
                                ++ name
                                |> qualifyPackageModule config.packageName
                    in
                    qualifiedNameToMatch range qualifiedName patterns

        Parser.TypeMatch range (Parser.InternalRef path name _) patterns ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
................................................................................
        Parser.TypeMatch range _ _ ->
            Err <| InvalidTypeMatch range


qualifyMatchValue :
    RunConfig
    -> Dict String TypeDefinition
    -> Dict String String
    -> Dict String (List String)
    -> SourceLocationRange
    -> String
    -> Set String
    -> ( String, Parser.TypeMatchValue )
    -> Result Problem ( String, TypeMatchValue )
qualifyMatchValue config qualifiedTypes aliases imports range typeName memberNames ( fieldName, matchValue ) =
    if Set.member fieldName memberNames then
        case matchValue of
            Parser.LiteralInt val ->
                Ok <| ( fieldName, LiteralInt val )

            Parser.LiteralType type_ ->
                let
                    qualifyTypeResult =
                        qualifyMemberType config aliases imports range type_
                in
                case qualifyTypeResult of
                    Ok qualifiedType ->
                        Ok <| ( fieldName, LiteralType qualifiedType )

                    Err err ->
                        Err err

            Parser.RecursiveMatch typeMatch ->
                case qualifyMatch config qualifiedTypes aliases imports typeMatch of
                    Err err ->
                        Err err

                    Ok match ->
                        Ok <| ( fieldName, RecursiveMatch match )

    else
................................................................................
            modRefs.imports
                |> Dict.toList
                |> List.find (\( _, v ) -> List.member name v)
                |> Maybe.map Tuple.first

        potentialCandidates =
            modRefs.imports
                |> Dict.filter (\_ v -> List.isEmpty v)
                |> Dict.keys
                |> List.filterMap resolveMod
                |> List.map (\mod -> ( mod, mod ++ "/" ++ name ))

        resolveMod mod =
            if String.startsWith "/" mod then
                Dict.get mod config.externalModules

Modified tests/Test/Qualifier.elm from [f67e00e051] to [b95204a661].

1810
1811
1812
1813
1814
1815
1816
1817




1818
1819
1820
1821
1822
1823
1824
....
1832
1833
1834
1835
1836
1837
1838




1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850





1851
1852
1853
1854
1855
1856
1857
....
1871
1872
1873
1874
1875
1876
1877
1878




1879
1880
1881
1882
1883
1884
1885
....
1893
1894
1895
1896
1897
1898
1899




1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911





1912
1913
1914
1915
1916
1917

































































































































1918
1919
1920
1921
1922
1923
1924
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature = AST.NotProvided




                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.PackageWord emptyRange [ "internal" ] "value"
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False




                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types = Dict.empty





                            , words =
                                Dict.fromList
                                    [ dummyWord "/external/package/mod/add"
                                    , dummyWord "internal/mod/value"
                                    ]
                            }
                    in
................................................................................
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature = AST.NotProvided




                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.fromList [ ( "internal", "internal/mod" ) ]
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.PackageWord emptyRange [ "internal" ] "value"
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False




                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types = Dict.empty





                            , words =
                                Dict.fromList
                                    [ dummyWord "/external/package/mod/add"
                                    , dummyWord "internal/mod/value"
                                    ]
                            }

































































































































                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Module imports" <|
                \_ ->







|
>
>
>
>







 







>
>
>
>











|
>
>
>
>
>







 







|
>
>
>
>







 







>
>
>
>











|
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
....
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
....
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
....
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature =
                                            AST.UserProvided
                                                { input = [ AST.InternalRef [ "ext" ] "Tipe" [] ]
                                                , output = [ AST.InternalRef [ "internal" ] "Tope" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.PackageWord emptyRange [ "internal" ] "value"
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                                |> Metadata.withType
                                                    [ Type.Custom "/external/package/mod/Tipe"
                                                    ]
                                                    [ Type.Custom "internal/mod/Tope" ]
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types =
                                [ dummyType "/external/package/mod/Tipe"
                                , dummyType "internal/mod/Tope"
                                ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words =
                                Dict.fromList
                                    [ dummyWord "/external/package/mod/add"
                                    , dummyWord "internal/mod/value"
                                    ]
                            }
                    in
................................................................................
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature =
                                            AST.UserProvided
                                                { input = [ AST.InternalRef [ "ext" ] "Tipe" [] ]
                                                , output = [ AST.InternalRef [ "internal" ] "Tope" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.fromList [ ( "internal", "internal/mod" ) ]
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.PackageWord emptyRange [ "internal" ] "value"
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                                |> Metadata.withType
                                                    [ Type.Custom "/external/package/mod/Tipe"
                                                    ]
                                                    [ Type.Custom "internal/mod/Tope" ]
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types =
                                [ dummyType "/external/package/mod/Tipe"
                                , dummyType "internal/mod/Tope"
                                ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words =
                                Dict.fromList
                                    [ dummyWord "/external/package/mod/add"
                                    , dummyWord "internal/mod/value"
                                    ]
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Module and function aliases in type match" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases =
                                        Dict.fromList
                                            [ ( "ext", "/mod" ) ]
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature = AST.NotProvided
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.fromList [ ( "internal", "internal/mod" ) ]
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (AST.InternalRef [ "ext" ] "Tipe" []) []
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                , ( AST.TypeMatch emptyRange (AST.InternalRef [ "internal" ] "Tope" []) []
                                                  , [ AST.Word emptyRange "drop" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "drop" ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "/external/package/mod/Tipe") []
                                                  , [ Builtin emptyRange Builtin.StackDrop ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.Custom "internal/mod/Tope") []
                                                  , [ Builtin emptyRange Builtin.StackDrop ]
                                                  )
                                                ]
                                                [ Builtin emptyRange Builtin.StackDrop ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types =
                                [ dummyType "/external/package/mod/Tipe"
                                , dummyType "internal/mod/Tope"
                                ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words = Dict.empty
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Type definition aliases" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases =
                                        Dict.fromList
                                            [ ( "ext", "/mod" )
                                            , ( "mod", "internal/mod" )
                                            ]
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types =
                                Dict.fromList
                                    [ ( "Tepip"
                                      , AST.CustomTypeDef
                                            emptyRange
                                            "Tepip"
                                            []
                                            [ ( "first", AST.InternalRef [ "ext" ] "Tipe" [] )
                                            , ( "second", AST.InternalRef [ "mod" ] "Tope" [] )
                                            ]
                                      )
                                    ]
                            , words = Dict.empty
                            }

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

                        inProgressAst =
                            { types =
                                [ dummyType "/external/package/mod/Tipe"
                                , dummyType "internal/mod/Tope"
                                ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words = Dict.empty
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Module imports" <|
                \_ ->