Stabel

Check-in [18cd6199cb]
Login
Overview
Comment:Qualifier can qualify type references to internal packages. Missing test for member types with internal reference.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 18cd6199cb7046fa7bbbe7170981e59e968483db8b10455abd2ab2408a8d7ce1
User & Date: robin.hansen on 2021-05-23 11:15:12
Other Links: branch diff | manifest | tags
Context
2021-05-24
15:12
Qualifier can qualify type references to external packages. check-in: 3b205d8501 user: robin.hansen tags: module-definition
2021-05-23
11:15
Qualifier can qualify type references to internal packages. Missing test for member types with inter... check-in: 18cd6199cb user: robin.hansen tags: module-definition
2021-05-21
14:42
Parser now understands module referenced types in pattern matches. check-in: 8a392255da user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Qualifier.elm from [680c118eed] to [995024408d].

253
254
255
256
257
258
259
260
261
262












263
264






265
266
267
268
269
270
271
272
273
...
529
530
531
532
533
534
535














































536
537
538
539
540
541
542

                        Err err ->
                            Err err

                Nothing ->
                    Err <| UnknownTypeRef range name

        Parser.InternalRef _ name _ ->
            case Dict.get name config.ast.types of
                Just _ ->












                    Ok <| Type.Custom (qualifyName config name)







                Nothing ->
                    Err <| UnknownTypeRef range name

        Parser.ExternalRef _ name _ ->
            case Dict.get name config.ast.types of
                Just _ ->
                    Ok <| Type.Custom (qualifyName config name)

                Nothing ->
................................................................................
            let
                qualifiedName =
                    qualifyName config name
            in
            case Dict.get qualifiedName qualifiedTypes of
                Just (CustomTypeDef _ _ gens members) ->
                    let














































                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
                            patterns







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

>
>
>
>
>
>
|
|







 







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







253
254
255
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
...
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
600
601
602
603
604
605
606

                        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 _ name _ ->
            case Dict.get name config.ast.types of
                Just _ ->
                    Ok <| Type.Custom (qualifyName config name)

                Nothing ->
................................................................................
            let
                qualifiedName =
                    qualifyName config name
            in
            case Dict.get qualifiedName qualifiedTypes of
                Just (CustomTypeDef _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

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

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

                                _ ->
                                    Type.CustomGeneric qualifiedName (List.map Type.Generic gens)
                    in
                    case qualifiedPatternsResult of
                        Ok qualifiedPatterns ->
                            Ok <| TypeMatch range actualType qualifiedPatterns

                        Err err ->
                            Err err

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

                    else
                        Err <| UnionTypeMatchWithPatterns range

                Nothing ->
                    Err <| UnknownTypeRef range qualifiedName

        Parser.TypeMatch range (Parser.InternalRef path name _) patterns ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
                        |> qualifyPackageModule config.packageName
            in
            case Dict.get qualifiedName config.inProgressAST.types of
                Just (CustomTypeDef _ _ gens members) ->
                    let
                        memberNames =
                            members
                                |> List.map Tuple.first
                                |> Set.fromList

                        qualifiedPatternsResult =
                            patterns

Modified tests/Test/Qualifier.elm from [e4846377b4] to [e393bec699].

1163
1164
1165
1166
1167
1168
1169
























1170
1171
1172
1173
1174
1175
1176
....
1272
1273
1274
1275
1276
1277
1278

























































































































































1279
1280
1281
1282
1283
1284
1285
                      , metadata =
                            Metadata.default
                                |> Metadata.isExposed False
                      , implementation =
                            SoloImpl []
                      }
                    )
























            in
            [ test "Qualifies word in internal package" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
................................................................................
                                    [ dummyWord "mod/add" ]
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst

























































































































































            , test "Qualifies word in external package" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =







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







 







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







1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
....
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
                      , metadata =
                            Metadata.default
                                |> Metadata.isExposed False
                      , implementation =
                            SoloImpl []
                      }
                    )

                dummyType name =
                    let
                        genericName =
                            name ++ "Generic"

                        unionName =
                            name ++ "Union"
                    in
                    [ ( name
                      , CustomTypeDef name emptyRange [] []
                      )
                    , ( genericName
                      , CustomTypeDef genericName emptyRange [ "a" ] []
                      )
                    , ( unionName
                      , UnionTypeDef unionName
                            emptyRange
                            []
                            [ Type.Custom name
                            , Type.CustomGeneric genericName [ Type.Generic "a" ]
                            ]
                      )
                    ]
            in
            [ test "Qualifies word in internal package" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
................................................................................
                                    [ dummyWord "mod/add" ]
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Qualifies type in internal package" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature =
                                            AST.UserProvided
                                                { input =
                                                    [ AST.InternalRef [ "mod" ] "Tipe" []
                                                    , AST.InternalRef [ "mod" ] "TipeGeneric" [ AST.Generic "a" ]
                                                    , AST.InternalRef [ "mod" ] "TipeUnion" []
                                                    ]
                                                , output = []
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Word emptyRange "drop"
                                                , AST.Word emptyRange "drop"
                                                , AST.Word emptyRange "drop"
                                                ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Custom "mod/Tipe"
                                                    , Type.CustomGeneric "mod/TipeGeneric" [ Type.Generic "a" ]
                                                    , Type.Union
                                                        [ Type.Custom "mod/Tipe"
                                                        , Type.CustomGeneric "mod/TipeGeneric" [ Type.Generic "a" ]
                                                        ]
                                                    ]
                                                    []
                                      , implementation =
                                            SoloImpl
                                                [ Builtin emptyRange Builtin.StackDrop
                                                , Builtin emptyRange Builtin.StackDrop
                                                , Builtin emptyRange Builtin.StackDrop
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types =
                                [ dummyType "mod/Tipe" ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words = Dict.empty
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "Qualifies type in internal package (multiword)" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , typeSignature =
                                            AST.UserProvided
                                                { input = [ AST.InternalRef [ "mod" ] "TipeUnion" [] ]
                                                , output = []
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (AST.InternalRef [ "mod" ] "Tipe" []) []
                                                  , [ AST.Word emptyRange "drop"
                                                    , AST.Word emptyRange "drop"
                                                    ]
                                                  )
                                                , ( AST.TypeMatch emptyRange (AST.InternalRef [ "mod" ] "TipeGeneric" [ AST.Generic "a" ]) []
                                                  , [ AST.Word emptyRange "drop"
                                                    , AST.Word emptyRange "drop"
                                                    ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "drop"
                                                , AST.Word emptyRange "drop"
                                                ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Union
                                                        [ Type.Custom "mod/Tipe"
                                                        , Type.CustomGeneric "mod/TipeGeneric" [ Type.Generic "a" ]
                                                        ]
                                                    ]
                                                    []
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "mod/Tipe") []
                                                  , [ Builtin emptyRange Builtin.StackDrop
                                                    , Builtin emptyRange Builtin.StackDrop
                                                    ]
                                                  )
                                                , ( TypeMatch emptyRange (Type.CustomGeneric "mod/TipeGeneric" [ Type.Generic "a" ]) []
                                                  , [ Builtin emptyRange Builtin.StackDrop
                                                    , Builtin emptyRange Builtin.StackDrop
                                                    ]
                                                  )
                                                ]
                                                [ Builtin emptyRange Builtin.StackDrop
                                                , Builtin emptyRange Builtin.StackDrop
                                                ]
                                      }
                                    ]
                            }

                        inProgressAst =
                            { types =
                                [ dummyType "mod/Tipe" ]
                                    |> List.concat
                                    |> Dict.fromList
                            , words = Dict.empty
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , Test.todo "Qualifies member type in internal package"
            , test "Qualifies word in external package" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =