Skip to content

Commit

Permalink
Fix compiler bug affecting Elm Parser module declarations
Browse files Browse the repository at this point in the history
This commit fixes a bug in the Elm compiler that resulted in invalid emission for a subset of module-level declarations with zero arguments. For example, this defective branch was taken when compiling declarations applying `Parser.Advanced.oneOf` as the root expression.
  • Loading branch information
Viir committed Sep 22, 2024
1 parent 46897c9 commit 6c88916
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 3 deletions.
18 changes: 16 additions & 2 deletions implement/pine/ElmTime/compile-elm-program/src/ElmCompiler.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3214,7 +3214,7 @@ emitRecursionDomain { exposedDeclarationsNames, allModuleDeclarations, importedF
exposedDeclarationsResult : Result String (List ( String, Pine.Value ))
exposedDeclarationsResult =
List.foldr
(\( declName, ( _, ( parameterCount, emittedValue ) ) ) aggregateResult ->
(\( declName, ( declExpression, ( parameterCount, emittedValue ) ) ) aggregateResult ->
if List.member declName recursionDomainExposedNames then
case aggregateResult of
Err err ->
Expand Down Expand Up @@ -3253,10 +3253,24 @@ emitRecursionDomain { exposedDeclarationsNames, allModuleDeclarations, importedF

Nothing ->
Pine.LiteralExpression emittedValue

innerIsJustReference : Bool
innerIsJustReference =
case declExpression of
FirCompiler.FunctionExpression [] innerFuncExpr ->
case innerFuncExpr of
FirCompiler.ReferenceExpression _ _ ->
True

_ ->
False

_ ->
False
in
case
evaluateAsIndependentExpression
(if parameterCount < 1 then
(if parameterCount == 0 && innerIsJustReference then
FirCompiler.emitWrapperForPartialApplicationZero
{ getFunctionInnerExpression = getFunctionInnerExpression
, getEnvFunctionsExpression = envFunctionsExpression
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/elm-stuff/
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/parser": "1.1.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module CompositeParser exposing (..)

import Parser.Advanced exposing ((|.), (|=))


negateToken : Parser.Advanced.Token ()
negateToken =
Parser.Advanced.Token "-" ()


oneOf_only_int : Parser.Advanced.Parser () () Int
oneOf_only_int =
Parser.Advanced.oneOf
[ Parser.Advanced.int () ()
]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Parser.Advanced.run (Parser.succeed "test") "unrelated"
Parser.Advanced.run (Parser.Advanced.succeed "test") "unrelated"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok []
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Parser.Advanced.run
(Parser.Advanced.symbol CompositeParser.negateToken)
"-"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parser.Advanced.run (Parser.Advanced.oneOf [ Parser.Advanced.int () () ]) "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testOneOf = Parser.Advanced.oneOf [ Parser.Advanced.int () () ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok 13
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parser.Advanced.run testOneOf "13"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok 17
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parser.Advanced.run CompositeParser.oneOf_only_int "17"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok 19
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parser.Advanced.run (CompositeParser.oneOf_only_int_with_param_for_problem ()) "19"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parser.run Parser.int "0"

0 comments on commit 6c88916

Please sign in to comment.