Stabel

Check-in [ed510a2c32]
Login
Overview
Comment:Fix all issues reported by elm-review.
Timelines: family | ancestors | descendants | both | trunk | releases | v0.2.1
Files: files | file ages | folders
SHA3-256: ed510a2c323fd628d232a4f79f5eb68eb85e035a91a4d3fe256b392737b37419
User & Date: robin.hansen on 2021-08-06 15:32:57
Other Links: manifest | tags
Context
2021-08-06
15:59
Add .npmignore check-in: 9051f68fda user: robin.hansen tags: trunk
15:32
Fix all issues reported by elm-review. check-in: ed510a2c32 user: robin.hansen tags: trunk, releases, v0.2.1
15:17
Add source refs to parser problems. check-in: c7f7dbae5f user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified review/src/ReviewConfig.elm from [ec821bfaf3] to [450fcd2476].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import Simplify


config : List Rule
config =
    [ Simplify.rule Simplify.defaults
    , NoUnused.CustomTypeConstructors.rule []
    , NoUnused.CustomTypeConstructorArgs.rule
    , NoUnused.Dependencies.rule
    , NoUnused.Exports.rule
    , NoUnused.Modules.rule
    , NoUnused.Parameters.rule
    , NoUnused.Patterns.rule
    , NoUnused.Variables.rule
    ]







<







12
13
14
15
16
17
18

19
20
21
22
23
24
25
import Simplify


config : List Rule
config =
    [ Simplify.rule Simplify.defaults
    , NoUnused.CustomTypeConstructors.rule []

    , NoUnused.Dependencies.rule
    , NoUnused.Exports.rule
    , NoUnused.Modules.rule
    , NoUnused.Parameters.rule
    , NoUnused.Patterns.rule
    , NoUnused.Variables.rule
    ]

Modified src/Stabel/Data/PackageMetadata.elm from [f79d36c524] to [ae50ecd50f].

72
73
74
75
76
77
78
79
80

resultDecodeAdapt : Result err ok -> Json.Decoder ok
resultDecodeAdapt result =
    case result of
        Ok value ->
            Json.succeed value

        Err err ->
            Json.fail "Something went wrong"







|

72
73
74
75
76
77
78
79
80

resultDecodeAdapt : Result err ok -> Json.Decoder ok
resultDecodeAdapt result =
    case result of
        Ok value ->
            Json.succeed value

        Err _ ->
            Json.fail "Something went wrong"

Modified src/Stabel/TypeChecker.elm from [fe98c63132] to [2a153ab55d].

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
....
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
....
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
    , TypeDefinition
    , TypeMatch(..)
    , TypeMatchValue(..)
    , run
    )

import Dict exposing (Dict)
import Dict.Extra as Dict
import List.Extra as List
import Set exposing (Set)
import Stabel.Data.Builtin as Builtin exposing (Builtin)
import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)
import Stabel.Data.TypeSignature as TypeSignature exposing (TypeSignature)
import Stabel.Qualifier as Qualifier
................................................................................
        |> Set.toList


collectUndeclaredGenericProblems : SourceLocationRange -> Set String -> List String -> List Problem
collectUndeclaredGenericProblems range listedGenerics memberTypes =
    memberTypes
        |> List.filter (\gen -> not (Set.member gen listedGenerics))
        |> List.map (\gen -> UndeclaredGeneric range gen listedGenerics)


cleanContext : Context -> Context
cleanContext ctx =
    { ctx
        | stackEffects = []
        , boundGenerics = Dict.empty
................................................................................
                    Nothing ->
                        constrainGenericsHelper
                            (Dict.insert infGen annotatedEl remappedGenerics)
                            annotatedRest
                            inferredRest
                            (annotatedEl :: acc)

        ( (_ as annotatedEl) :: annotatedRest, (Type.StackRange infGen) :: inferredRest ) ->
            case Dict.get infGen remappedGenerics of
                Just val ->
                    constrainGenericsHelper remappedGenerics annotatedRest inferredRest (val :: acc)

                Nothing ->
                    constrainGenericsHelper
                        (Dict.insert infGen annotatedEl remappedGenerics)
................................................................................
                (resolveType context expected)
                (resolveType context actual)
    in
    case effects of
        [] ->
            ( context
            , { functionType
                | input = functionType.input
                , output = List.reverse functionType.output
              }
            )

        (Pop ((Type.StackRange rangeName) as type_)) :: remainingEffects ->
            case Dict.get rangeName context.boundStackRanges of
                Just needToPop ->
                    functionTypeFromStackEffectsHelper untypedDef (List.map Pop needToPop ++ remainingEffects) ( context, functionType )
................................................................................
                                let
                                    ( finalCtx, allBoundToSame ) =
                                        List.foldl helper ( context, True ) rest

                                    helper t ( ctx, oldTruth ) =
                                        let
                                            ( newCtx, thisTruth ) =
                                                compatibleTypes context firstType t
                                        in
                                        ( newCtx, oldTruth && thisTruth )
                                in
                                if allBoundToSame then
                                    compatibleTypes finalCtx firstType rhs

                                else







<







 







|







 







|







 







<
|







 







|







7
8
9
10
11
12
13

14
15
16
17
18
19
20
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
....
1345
1346
1347
1348
1349
1350
1351

1352
1353
1354
1355
1356
1357
1358
1359
....
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
    , TypeDefinition
    , TypeMatch(..)
    , TypeMatchValue(..)
    , run
    )

import Dict exposing (Dict)

import List.Extra as List
import Set exposing (Set)
import Stabel.Data.Builtin as Builtin exposing (Builtin)
import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)
import Stabel.Data.TypeSignature as TypeSignature exposing (TypeSignature)
import Stabel.Qualifier as Qualifier
................................................................................
        |> Set.toList


collectUndeclaredGenericProblems : SourceLocationRange -> Set String -> List String -> List Problem
collectUndeclaredGenericProblems range listedGenerics memberTypes =
    memberTypes
        |> List.filter (\gen -> not (Set.member gen listedGenerics))
        |> List.map (\gen -> UndeclaredGeneric range gen)


cleanContext : Context -> Context
cleanContext ctx =
    { ctx
        | stackEffects = []
        , boundGenerics = Dict.empty
................................................................................
                    Nothing ->
                        constrainGenericsHelper
                            (Dict.insert infGen annotatedEl remappedGenerics)
                            annotatedRest
                            inferredRest
                            (annotatedEl :: acc)

        ( annotatedEl :: annotatedRest, (Type.StackRange infGen) :: inferredRest ) ->
            case Dict.get infGen remappedGenerics of
                Just val ->
                    constrainGenericsHelper remappedGenerics annotatedRest inferredRest (val :: acc)

                Nothing ->
                    constrainGenericsHelper
                        (Dict.insert infGen annotatedEl remappedGenerics)
................................................................................
                (resolveType context expected)
                (resolveType context actual)
    in
    case effects of
        [] ->
            ( context
            , { functionType

                | output = List.reverse functionType.output
              }
            )

        (Pop ((Type.StackRange rangeName) as type_)) :: remainingEffects ->
            case Dict.get rangeName context.boundStackRanges of
                Just needToPop ->
                    functionTypeFromStackEffectsHelper untypedDef (List.map Pop needToPop ++ remainingEffects) ( context, functionType )
................................................................................
                                let
                                    ( finalCtx, allBoundToSame ) =
                                        List.foldl helper ( context, True ) rest

                                    helper t ( ctx, oldTruth ) =
                                        let
                                            ( newCtx, thisTruth ) =
                                                compatibleTypes ctx firstType t
                                        in
                                        ( newCtx, oldTruth && thisTruth )
                                in
                                if allBoundToSame then
                                    compatibleTypes finalCtx firstType rhs

                                else

Modified src/Stabel/TypeChecker/Problem.elm from [6c347f614c] to [f356902d82].

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
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module Stabel.TypeChecker.Problem exposing
    ( Problem(..)
    , sourceLocationRef
    , toString
    )

import Set exposing (Set)
import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)


type Problem
    = UndeclaredGeneric SourceLocationRange String (Set String)
    | TypeError SourceLocationRange String FunctionType FunctionType
    | UnexpectedType SourceLocationRange String Type Type
    | InconsistentWhens SourceLocationRange String
    | MissingTypeAnnotationInRecursiveCallStack SourceLocationRange String
    | InexhaustiveMultiFunction SourceLocationRange (List (List Type))
    | BadEntryPoint SourceLocationRange String FunctionType FunctionType


toString : String -> Problem -> String
toString source problem =
    case problem of
        UndeclaredGeneric range generic _ ->
            ">> "
                ++ range.source
                ++ "\n\n"
                ++ SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "Generic variable '"
                ++ generic
................................................................................
                ++ "\n\nHowever, it seems that the actual type is:\n\n"
                ++ Type.functionTypeToString expected


sourceLocationRef : Problem -> String
sourceLocationRef problem =
    case problem of
        UndeclaredGeneric range _ _ ->
            range.source

        TypeError range _ _ _ ->
            range.source

        UnexpectedType range _ _ _ ->
            range.source






<





|











|







 







|







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
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Stabel.TypeChecker.Problem exposing
    ( Problem(..)
    , sourceLocationRef
    , toString
    )


import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)


type Problem
    = UndeclaredGeneric SourceLocationRange String
    | TypeError SourceLocationRange String FunctionType FunctionType
    | UnexpectedType SourceLocationRange String Type Type
    | InconsistentWhens SourceLocationRange String
    | MissingTypeAnnotationInRecursiveCallStack SourceLocationRange String
    | InexhaustiveMultiFunction SourceLocationRange (List (List Type))
    | BadEntryPoint SourceLocationRange String FunctionType FunctionType


toString : String -> Problem -> String
toString source problem =
    case problem of
        UndeclaredGeneric range generic ->
            ">> "
                ++ range.source
                ++ "\n\n"
                ++ SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "Generic variable '"
                ++ generic
................................................................................
                ++ "\n\nHowever, it seems that the actual type is:\n\n"
                ++ Type.functionTypeToString expected


sourceLocationRef : Problem -> String
sourceLocationRef problem =
    case problem of
        UndeclaredGeneric range _ ->
            range.source

        TypeError range _ _ _ ->
            range.source

        UnexpectedType range _ _ _ ->
            range.source

Modified src/Stabel/Wasm.elm from [224b72ee42] to [3afad62349].

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346


type Type
    = Int32


typeToString : Type -> String
typeToString type_ =
    case type_ of
        Int32 ->
            "i32"


type Instruction
    = NoOp
    | Batch (List Instruction)
    | Block (List Instruction)
    | Loop (List Instruction)
    | Break Int
    | BreakIf Int
    | Return
    | Call Int String
    | CallIndirect
................................................................................
    , Str ")"
    ]


formatInstruction : Instruction -> FormatHint
formatInstruction ins =
    case ins of
        NoOp ->
            Str "nop"

        Batch insList ->
            BatchFormat <| List.map formatInstruction insList

        Block insList ->
            BatchFormat
                [ Str "(block"
                , Indent <| List.map formatInstruction insList







|
<
<
|



<
|







 







<
<
<







65
66
67
68
69
70
71
72


73
74
75
76

77
78
79
80
81
82
83
84
...
327
328
329
330
331
332
333



334
335
336
337
338
339
340


type Type
    = Int32


typeToString : Type -> String
typeToString _ =


    "i32"


type Instruction

    = Batch (List Instruction)
    | Block (List Instruction)
    | Loop (List Instruction)
    | Break Int
    | BreakIf Int
    | Return
    | Call Int String
    | CallIndirect
................................................................................
    , Str ")"
    ]


formatInstruction : Instruction -> FormatHint
formatInstruction ins =
    case ins of



        Batch insList ->
            BatchFormat <| List.map formatInstruction insList

        Block insList ->
            BatchFormat
                [ Str "(block"
                , Indent <| List.map formatInstruction insList

Modified tests/Test/EntryPoints.elm from [1b94a90359] to [bf8aaed711].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Test.EntryPoints exposing (suite)

import CLI
import Expect
import Test exposing (Test, describe, test)
import TestCompiler


suite : Test
suite =
    describe "EntryPoints"
        [ test "Dummy test to see that code not covered by test at least compiles" <|
            \_ ->
                Expect.pass
        ]


<


<









1
2

3
4

5
6
7
8
9
10
11
12
13
module Test.EntryPoints exposing (suite)


import Expect
import Test exposing (Test, describe, test)



suite : Test
suite =
    describe "EntryPoints"
        [ test "Dummy test to see that code not covered by test at least compiles" <|
            \_ ->
                Expect.pass
        ]

Modified tests/Test/PackageLoader.elm from [0e4aad1e63] to [b7a13acee6].

1
2
3
4
5
6
7
8
9
10
11
12
13
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
module Test.PackageLoader exposing (suite)

import Dict exposing (Dict)
import Dict.Extra as Dict
import Expect exposing (Expectation)
import List.Extra as List
import Set
import Stabel.Data.Builtin as Builtin
import Stabel.Data.PackagePath as PackagePath
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.TypeSignature as TypeSignature
import Stabel.PackageLoader as PackageLoader
import Stabel.Qualifier as Qualifier
................................................................................
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err err ->
                            let
                                _ =
                                    Debug.log "err" err
                            in
                            Expect.fail "Did not expect failure"

                        Ok _ ->
                            Expect.pass
            ]
        ]






<







 







|
<
<
<
<







1
2
3
4
5

6
7
8
9
10
11
12
...
173
174
175
176
177
178
179
180




181
182
183
184
185
186
187
module Test.PackageLoader exposing (suite)

import Dict exposing (Dict)
import Dict.Extra as Dict
import Expect exposing (Expectation)

import Set
import Stabel.Data.Builtin as Builtin
import Stabel.Data.PackagePath as PackagePath
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.TypeSignature as TypeSignature
import Stabel.PackageLoader as PackageLoader
import Stabel.Qualifier as Qualifier
................................................................................
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err _ ->




                            Expect.fail "Did not expect failure"

                        Ok _ ->
                            Expect.pass
            ]
        ]

Modified tests/Test/Parser/Errors.elm from [c8175b72d4] to [02d836c7d4].

1
2
3
4
5
6
7
8
9
10
11
module Test.Parser.Errors exposing (..)

import Expect exposing (Expectation)
import Stabel.Parser exposing (..)
import Stabel.Parser.Problem exposing (Problem(..))
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (compile)


suite : Test
suite =



<







1
2
3

4
5
6
7
8
9
10
module Test.Parser.Errors exposing (..)

import Expect exposing (Expectation)

import Stabel.Parser.Problem exposing (Problem(..))
import Test exposing (Test, describe, test)
import Test.Parser.Util exposing (compile)


suite : Test
suite =

Modified tests/Test/Qualifier/Errors.elm from [70f07cc76d] to [904e91d942].

1
2
3
4
5
6
7
8
9
10
11
module Test.Qualifier.Errors exposing (suite)

import Dict
import Dict.Extra as Dict
import Expect exposing (Expectation)
import Set
import Stabel.Parser as Parser
import Stabel.Qualifier as Qualifier
import Stabel.Qualifier.Problem exposing (Problem(..))
import Test exposing (Test, describe, test)




<







1
2
3

4
5
6
7
8
9
10
module Test.Qualifier.Errors exposing (suite)

import Dict

import Expect exposing (Expectation)
import Set
import Stabel.Parser as Parser
import Stabel.Qualifier as Qualifier
import Stabel.Qualifier.Problem exposing (Problem(..))
import Test exposing (Test, describe, test)

Modified tests/Test/Qualifier/ModuleResolution.elm from [bdf59b4bde] to [3a57acc6b9].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Test.Qualifier.ModuleResolution exposing (suite)

import Dict
import Expect exposing (Expectation)
import Set
import Stabel.Parser as Parser
import Stabel.Parser.ModuleDefinition as ModuleDefinition
import Stabel.Parser.Problem as Parser
import Stabel.Qualifier exposing (..)
import Stabel.Qualifier.Problem as Problem exposing (Problem)
import Test exposing (Test, describe, test)
import Test.Qualifier.Util as Util


suite : Test







<







1
2
3
4
5
6
7

8
9
10
11
12
13
14
module Test.Qualifier.ModuleResolution exposing (suite)

import Dict
import Expect exposing (Expectation)
import Set
import Stabel.Parser as Parser
import Stabel.Parser.ModuleDefinition as ModuleDefinition

import Stabel.Qualifier exposing (..)
import Stabel.Qualifier.Problem as Problem exposing (Problem)
import Test exposing (Test, describe, test)
import Test.Qualifier.Util as Util


suite : Test

Modified tests/Test/Qualifier/Util.elm from [1b719649e5] to [ab2d8b6fc6].

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
    ( emptyAst
    , expectModuleOutput
    , expectQualification
    , stripLocations
    )

import Dict
import Dict.Extra as Dict
import Expect exposing (Expectation)
import Set
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Parser as Parser
import Stabel.Qualifier as AST
    exposing
        ( AST
        , FunctionDefinition
        , FunctionImplementation(..)
        , Node(..)
        , TypeDefinition
        , TypeMatch(..)
        , TypeMatchCond(..)
        , TypeMatchValue(..)
        )









<









|







2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    ( emptyAst
    , expectModuleOutput
    , expectQualification
    , stripLocations
    )

import Dict

import Expect exposing (Expectation)
import Set
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Parser as Parser
import Stabel.Qualifier as AST
    exposing
        ( AST
        , FunctionDefinition
        , FunctionImplementation(..)
        , Node
        , TypeDefinition
        , TypeMatch(..)
        , TypeMatchCond(..)
        , TypeMatchValue(..)
        )


Modified tests/Test/TypeChecker.elm from [2497206fef] to [46133d700a].

1
2
3
4
5
6
7
8
9
10
module Test.TypeChecker exposing (suite)

import Dict
import Dict.Extra as Dict
import Stabel.Data.Builtin as Builtin
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.Type as Type
import Stabel.TypeChecker exposing (..)
import Test exposing (Test, describe, test)
import Test.TypeChecker.Util


<







1
2

3
4
5
6
7
8
9
module Test.TypeChecker exposing (suite)


import Dict.Extra as Dict
import Stabel.Data.Builtin as Builtin
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.Type as Type
import Stabel.TypeChecker exposing (..)
import Test exposing (Test, describe, test)
import Test.TypeChecker.Util

Modified tests/Test/TypeChecker/Errors.elm from [aeee6ce25c] to [7507f111d0].

1
2
3
4
5
6
7
8
9
10
11
12
13
...
418
419
420
421
422
423
424
425
426
427
428
429
module Test.TypeChecker.Errors exposing (suite)

import Expect
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.Type as Type
import Stabel.Qualifier exposing (..)
import Stabel.TypeChecker.Problem as Problem exposing (Problem)
import Test exposing (Test, describe, test)
import Test.TypeChecker.Util as Util exposing (checkForError)


suite : Test
suite =
................................................................................
            ]
        ]


undeclaredGenericError : String -> Problem -> Bool
undeclaredGenericError generic problem =
    case problem of
        Problem.UndeclaredGeneric _ problemGeneric _ ->
            generic == problemGeneric

        _ ->
            False





<







 







|




1
2
3
4
5

6
7
8
9
10
11
12
...
417
418
419
420
421
422
423
424
425
426
427
428
module Test.TypeChecker.Errors exposing (suite)

import Expect
import Stabel.Data.SourceLocation exposing (emptyRange)
import Stabel.Data.Type as Type

import Stabel.TypeChecker.Problem as Problem exposing (Problem)
import Test exposing (Test, describe, test)
import Test.TypeChecker.Util as Util exposing (checkForError)


suite : Test
suite =
................................................................................
            ]
        ]


undeclaredGenericError : String -> Problem -> Bool
undeclaredGenericError generic problem =
    case problem of
        Problem.UndeclaredGeneric _ problemGeneric ->
            generic == problemGeneric

        _ ->
            False

Modified tests/Test/TypeChecker/Unions.elm from [c59f8732f2] to [c778cb62b9].

1
2
3
4
5
6
7
8
9
10
module Test.TypeChecker.Unions exposing (suite)

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


<







1
2

3
4
5
6
7
8
9
module Test.TypeChecker.Unions exposing (suite)


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