Play

Check-in [e503e3ec36]
Login
Overview
Comment:Qualify member types of structs.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: e503e3ec3658a0b756fbe5572b9e0e502aab595e9999d68e6cc86ae2242a5f2b
User & Date: robin.hansen on 2021-02-07 12:02:18
Other Links: branch diff | manifest | tags
Context
2021-02-09
09:40
Prepare data structures and add test for returning modules to load from qualifier step. check-in: a7c9bebc32 user: robin.hansen tags: modules
2021-02-07
12:02
Qualify member types of structs. check-in: e503e3ec36 user: robin.hansen tags: modules
11:41
Implement name mangling. check-in: 61c06857ee user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Qualifier.elm from [6fc02dba27] to [661a5ac53d].

158
159
160
161
162
163
164













165







166
167
168
169
170
171
172
173
174
175
    -> ( List Problem, Dict String TypeDefinition )
qualifyType config typeDef ( errors, acc ) =
    case typeDef of
        Parser.CustomTypeDef range name generics members ->
            let
                qualifiedName =
                    qualifyName config name













            in







            ( errors
            , Dict.insert qualifiedName (CustomTypeDef qualifiedName range generics members) acc
            )

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

                qualifiedMemberTypesResult =







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

>
>
>
>
>
>
>
|
|
|







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
    -> ( 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 )

                        Err err ->
                            Err err
            in
            case qualifiedMemberResult of
                Err err ->
                    ( err :: errors
                    , acc
                    )

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

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

                qualifiedMemberTypesResult =

Modified tests/Test/Qualifier/Error.elm from [493e3d364c] to [e0d5fe30cb].

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
84
85
86
87
88
89
90














91
92
93
94
95





96





97
98












99
100
101
102
103




















104
105
106
107
108
109
110
                                                , AST.Word emptyRange "dec"
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "="
                                                ]
                                      }
                                    ]
                            }

                        noSuchReferenceError name problem =
                            case problem of
                                UnknownWordRef _ problemName ->
                                    name == problemName

                                _ ->
                                    False
                    in
                    checkForError (noSuchReferenceError "dec") ast
            , test "Type" <|
                \_ ->
                    let
                        ast =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
................................................................................
                                                , AST.Word emptyRange "inc"
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "="
                                                ]
                                      }
                                    ]
                            }















                        noSuchReferenceError name problem =
                            case problem of
                                UnknownTypeRef _ problemName ->
                                    name == problemName











                                _ ->
                                    False












                    in
                    checkForError (noSuchReferenceError "Ints") ast
            ]
        ]






















checkForError : (Problem -> Bool) -> AST.AST -> Expectation
checkForError fn source =
    let
        result =
            run
                { packageName = ""







<
<
<
<
<
<
<
<

|







 







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

|



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







43
44
45
46
47
48
49








50
51
52
53
54
55
56
57
58
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
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
                                                , AST.Word emptyRange "dec"
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "="
                                                ]
                                      }
                                    ]
                            }








                    in
                    checkForError (noSuchWordReferenceError "dec") ast
            , test "Type" <|
                \_ ->
                    let
                        ast =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
................................................................................
                                                , AST.Word emptyRange "inc"
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "="
                                                ]
                                      }
                                    ]
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Ints") ast
            , test "Wrong reference within union definition" <|
                \_ ->
                    let
                        ast =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef
                                        emptyRange
                                        "USMoney"
                                        []
                                        [ Type.Custom "Dollar"
                                        , Type.Custom "Cent"
                                        ]




                                    , AST.CustomTypeDef
                                        emptyRange
                                        "Dollar"
                                        []
                                        [ ( "dollar-value", Type.Int ) ]
                                    ]
                            , words = Dict.empty
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Cent") ast
            , test "Wrong reference within custom type definition" <|
                \_ ->

                    let
                        ast =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.CustomTypeDef
                                        emptyRange
                                        "BoxWrapper"
                                        []
                                        [ ( "box", Type.Custom "Box" ) ]
                                    ]
                            , words = Dict.empty
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Box") ast
            ]
        ]


noSuchWordReferenceError : String -> Problem -> Bool
noSuchWordReferenceError name problem =
    case problem of
        UnknownWordRef _ problemName ->
            name == problemName

        _ ->
            False


noSuchTypeReferenceError : String -> Problem -> Bool
noSuchTypeReferenceError name problem =
    case problem of
        UnknownTypeRef _ problemName ->
            name == problemName

        _ ->
            False


checkForError : (Problem -> Bool) -> AST.AST -> Expectation
checkForError fn source =
    let
        result =
            run
                { packageName = ""