Play

Check-in [a52bd3c1b1]
Login
Overview
Comment:Make sure generics used in custom type or union is listed as part of the type signature.
Timelines: family | ancestors | descendants | both | generic-types-and-unions
Files: files | file ages | folders
SHA3-256: a52bd3c1b19b16155c53e772cf600842ffb82640765cbbb9226bebcd4466950c
User & Date: robin.hansen on 2020-08-02 08:52:36
Other Links: branch diff | manifest | tags
Context
2020-08-03
13:54
Fix remaining issues with generic types and codegen. Closed-Leaf check-in: 5779464d2f user: robin.hansen tags: generic-types-and-unions
2020-08-02
08:52
Make sure generics used in custom type or union is listed as part of the type signature. check-in: a52bd3c1b1 user: robin.hansen tags: generic-types-and-unions
08:29
Add failing tests that needs to be fixed before merging into trunk. check-in: 21f1021f18 user: robin.hansen tags: generic-types-and-unions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/TypeChecker.elm from [573567c000] to [e4089295ab].

80
81
82
83
84
85
86























87
88
89
90
91
92
93
94
95
96




















97
98
99
100
101
102
103
                        Qualifier.CustomTypeDef name generics members ->
                            CustomTypeDef name generics members

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























    in
    { types = concreteTypes
    , typedWords = Dict.empty
    , untypedWords = ast.words
    , stackEffects = []
    , boundGenerics = Dict.empty
    , boundStackRanges = Dict.empty
    , errors = []
    }






















typeCheck : Qualifier.AST -> Result () AST
typeCheck ast =
    typeCheckHelper (initContext ast) ast


typeCheckHelper : Context -> Qualifier.AST -> Result () AST







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







|


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







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
                        Qualifier.CustomTypeDef name generics members ->
                            CustomTypeDef name generics members

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

        genericErrors t =
            let
                ( listedGenerics, memberTypes ) =
                    case t of
                        CustomTypeDef _ generics members ->
                            ( Set.fromList generics
                            , List.map Tuple.second members
                            )

                        UnionTypeDef _ generics mts ->
                            ( Set.fromList generics, mts )

                usedGenerics =
                    List.map referencedGenerics memberTypes
                        |> List.foldl Set.union Set.empty
                        |> Set.toList
            in
            if List.all (\gen -> Set.member gen listedGenerics) usedGenerics then
                Nothing

            else
                Just ()
    in
    { types = concreteTypes
    , typedWords = Dict.empty
    , untypedWords = ast.words
    , stackEffects = []
    , boundGenerics = Dict.empty
    , boundStackRanges = Dict.empty
    , errors = List.filterMap genericErrors (Dict.values concreteTypes)
    }


referencedGenerics : Type -> Set String
referencedGenerics t =
    case t of
        Type.Generic val ->
            Set.singleton val

        Type.CustomGeneric _ members ->
            members
                |> List.map referencedGenerics
                |> List.foldl Set.union Set.empty

        Type.Union members ->
            members
                |> List.map referencedGenerics
                |> List.foldl Set.union Set.empty

        _ ->
            Set.empty


typeCheck : Qualifier.AST -> Result () AST
typeCheck ast =
    typeCheckHelper (initContext ast) ast


typeCheckHelper : Context -> Qualifier.AST -> Result () AST