mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Fix closure transformer tests to return closures directly
Update the closure transformer snapshot tests to return closures
themselves rather than applying them. This allows the MONO section
to show the actual closure transformation structure:
- #1({x: x}) for single capture
- #1({}) for pure lambdas with empty record
- #1({a: a, b: b}) for multiple captures
- #addX, #addY for named closures
The previous tests applied the closures which caused constant folding
to reduce them to numeric values, hiding the transformation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
10f0994cd5
commit
28f8a5a993
5 changed files with 179 additions and 112 deletions
|
|
@ -8,21 +8,23 @@ type=mono
|
|||
{
|
||||
a = 1
|
||||
b = 2
|
||||
f = |x| a + b + x
|
||||
f(3)
|
||||
|x| a + b + x
|
||||
}
|
||||
~~~
|
||||
# MONO
|
||||
~~~roc
|
||||
6 : Dec
|
||||
{
|
||||
a = 1
|
||||
b = 2
|
||||
#1({a: a, b: b})
|
||||
} : c -> c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]
|
||||
~~~
|
||||
# FORMATTED
|
||||
~~~roc
|
||||
{
|
||||
a = 1
|
||||
b = 2
|
||||
f = |x| a + b + x
|
||||
f(3)
|
||||
|x| a + b + x
|
||||
}
|
||||
~~~
|
||||
# EXPECTED
|
||||
|
|
@ -34,8 +36,7 @@ NIL
|
|||
OpenCurly,
|
||||
LowerIdent,OpAssign,Int,
|
||||
LowerIdent,OpAssign,Int,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,OpPlus,LowerIdent,
|
||||
LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,OpPlus,LowerIdent,
|
||||
CloseCurly,
|
||||
EndOfFile,
|
||||
~~~
|
||||
|
|
@ -49,25 +50,41 @@ EndOfFile,
|
|||
(s-decl
|
||||
(p-ident (raw "b"))
|
||||
(e-int (raw "2")))
|
||||
(s-decl
|
||||
(p-ident (raw "f"))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "x")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "x")))
|
||||
(e-binop (op "+")
|
||||
(e-binop (op "+")
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "a"))
|
||||
(e-ident (raw "b")))
|
||||
(e-ident (raw "x")))))
|
||||
(e-apply
|
||||
(e-ident (raw "f"))
|
||||
(e-int (raw "3")))))
|
||||
(e-ident (raw "a"))
|
||||
(e-ident (raw "b")))
|
||||
(e-ident (raw "x"))))))
|
||||
~~~
|
||||
# CANONICALIZE
|
||||
~~~clojure
|
||||
(e-num (value "6"))
|
||||
(e-block
|
||||
(s-let
|
||||
(p-assign (ident "a"))
|
||||
(e-num (value "1")))
|
||||
(s-let
|
||||
(p-assign (ident "b"))
|
||||
(e-num (value "2")))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "a"))
|
||||
(capture (ident "b")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "x")))
|
||||
(e-binop (op "add")
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "a")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "b"))))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "x")))))))
|
||||
~~~
|
||||
# TYPES
|
||||
~~~clojure
|
||||
(expr (type "c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"))
|
||||
(expr (type "c -> c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"))
|
||||
~~~
|
||||
|
|
|
|||
|
|
@ -7,20 +7,21 @@ type=mono
|
|||
~~~roc
|
||||
{
|
||||
x = 42
|
||||
f = |y| x + y
|
||||
f(10)
|
||||
|y| x + y
|
||||
}
|
||||
~~~
|
||||
# MONO
|
||||
~~~roc
|
||||
52 : Dec
|
||||
{
|
||||
x = 42
|
||||
#1({x: x})
|
||||
} : a -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]
|
||||
~~~
|
||||
# FORMATTED
|
||||
~~~roc
|
||||
{
|
||||
x = 42
|
||||
f = |y| x + y
|
||||
f(10)
|
||||
|y| x + y
|
||||
}
|
||||
~~~
|
||||
# EXPECTED
|
||||
|
|
@ -31,8 +32,7 @@ NIL
|
|||
~~~zig
|
||||
OpenCurly,
|
||||
LowerIdent,OpAssign,Int,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,
|
||||
LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,
|
||||
CloseCurly,
|
||||
EndOfFile,
|
||||
~~~
|
||||
|
|
@ -43,23 +43,32 @@ EndOfFile,
|
|||
(s-decl
|
||||
(p-ident (raw "x"))
|
||||
(e-int (raw "42")))
|
||||
(s-decl
|
||||
(p-ident (raw "f"))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "y")))
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "x"))
|
||||
(e-ident (raw "y")))))
|
||||
(e-apply
|
||||
(e-ident (raw "f"))
|
||||
(e-int (raw "10")))))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "y")))
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "x"))
|
||||
(e-ident (raw "y"))))))
|
||||
~~~
|
||||
# CANONICALIZE
|
||||
~~~clojure
|
||||
(e-num (value "52"))
|
||||
(e-block
|
||||
(s-let
|
||||
(p-assign (ident "x"))
|
||||
(e-num (value "42")))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "x")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "y")))
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "x")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "y")))))))
|
||||
~~~
|
||||
# TYPES
|
||||
~~~clojure
|
||||
(expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
(expr (type "a -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
~~~
|
||||
|
|
|
|||
|
|
@ -10,12 +10,18 @@ type=mono
|
|||
y = 20
|
||||
addX = |a| a + x
|
||||
addY = |b| b + y
|
||||
addX(1) + addY(2)
|
||||
(addX, addY)
|
||||
}
|
||||
~~~
|
||||
# MONO
|
||||
~~~roc
|
||||
33 : Dec
|
||||
{
|
||||
x = 10
|
||||
y = 20
|
||||
addX = #addX({x: x})
|
||||
addY = #addY({y: y})
|
||||
(addX, addY)
|
||||
} : (c -> c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])], c -> c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])])
|
||||
~~~
|
||||
# FORMATTED
|
||||
~~~roc
|
||||
|
|
@ -24,7 +30,7 @@ type=mono
|
|||
y = 20
|
||||
addX = |a| a + x
|
||||
addY = |b| b + y
|
||||
addX(1) + addY(2)
|
||||
(addX, addY)
|
||||
}
|
||||
~~~
|
||||
# EXPECTED
|
||||
|
|
@ -38,7 +44,7 @@ LowerIdent,OpAssign,Int,
|
|||
LowerIdent,OpAssign,Int,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,
|
||||
LowerIdent,NoSpaceOpenRound,Int,CloseRound,OpPlus,LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
OpenRound,LowerIdent,Comma,LowerIdent,CloseRound,
|
||||
CloseCurly,
|
||||
EndOfFile,
|
||||
~~~
|
||||
|
|
@ -68,19 +74,53 @@ EndOfFile,
|
|||
(e-binop (op "+")
|
||||
(e-ident (raw "b"))
|
||||
(e-ident (raw "y")))))
|
||||
(e-binop (op "+")
|
||||
(e-apply
|
||||
(e-ident (raw "addX"))
|
||||
(e-int (raw "1")))
|
||||
(e-apply
|
||||
(e-ident (raw "addY"))
|
||||
(e-int (raw "2"))))))
|
||||
(e-tuple
|
||||
(e-ident (raw "addX"))
|
||||
(e-ident (raw "addY")))))
|
||||
~~~
|
||||
# CANONICALIZE
|
||||
~~~clojure
|
||||
(e-num (value "33"))
|
||||
(e-block
|
||||
(s-let
|
||||
(p-assign (ident "x"))
|
||||
(e-num (value "10")))
|
||||
(s-let
|
||||
(p-assign (ident "y"))
|
||||
(e-num (value "20")))
|
||||
(s-let
|
||||
(p-assign (ident "addX"))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "x")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "a")))
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "a")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "x")))))))
|
||||
(s-let
|
||||
(p-assign (ident "addY"))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "y")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "b")))
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "b")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "y")))))))
|
||||
(e-tuple
|
||||
(elems
|
||||
(e-lookup-local
|
||||
(p-assign (ident "addX")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "addY"))))))
|
||||
~~~
|
||||
# TYPES
|
||||
~~~clojure
|
||||
(expr (type "c where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"))
|
||||
(expr (type "(c -> c, d -> d) where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]"))
|
||||
~~~
|
||||
|
|
|
|||
|
|
@ -7,22 +7,21 @@ type=mono
|
|||
~~~roc
|
||||
{
|
||||
x = 10
|
||||
makeAdder = |y| |z| x + y + z
|
||||
addFive = makeAdder(5)
|
||||
addFive(3)
|
||||
|y| |z| x + y + z
|
||||
}
|
||||
~~~
|
||||
# MONO
|
||||
~~~roc
|
||||
18 : Dec
|
||||
{
|
||||
x = 10
|
||||
#1({x: x})
|
||||
} : a -> (a -> a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]
|
||||
~~~
|
||||
# FORMATTED
|
||||
~~~roc
|
||||
{
|
||||
x = 10
|
||||
makeAdder = |y| |z| x + y + z
|
||||
addFive = makeAdder(5)
|
||||
addFive(3)
|
||||
|y| |z| x + y + z
|
||||
}
|
||||
~~~
|
||||
# EXPECTED
|
||||
|
|
@ -33,9 +32,7 @@ NIL
|
|||
~~~zig
|
||||
OpenCurly,
|
||||
LowerIdent,OpAssign,Int,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,OpPlus,LowerIdent,
|
||||
LowerIdent,OpAssign,LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
OpBar,LowerIdent,OpBar,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,OpPlus,LowerIdent,
|
||||
CloseCurly,
|
||||
EndOfFile,
|
||||
~~~
|
||||
|
|
@ -46,33 +43,47 @@ EndOfFile,
|
|||
(s-decl
|
||||
(p-ident (raw "x"))
|
||||
(e-int (raw "10")))
|
||||
(s-decl
|
||||
(p-ident (raw "makeAdder"))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "y")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "y")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "z")))
|
||||
(p-ident (raw "z")))
|
||||
(e-binop (op "+")
|
||||
(e-binop (op "+")
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "x"))
|
||||
(e-ident (raw "y")))
|
||||
(e-ident (raw "z"))))))
|
||||
(s-decl
|
||||
(p-ident (raw "addFive"))
|
||||
(e-apply
|
||||
(e-ident (raw "makeAdder"))
|
||||
(e-int (raw "5"))))
|
||||
(e-apply
|
||||
(e-ident (raw "addFive"))
|
||||
(e-int (raw "3")))))
|
||||
(e-ident (raw "x"))
|
||||
(e-ident (raw "y")))
|
||||
(e-ident (raw "z")))))))
|
||||
~~~
|
||||
# CANONICALIZE
|
||||
~~~clojure
|
||||
(e-num (value "18"))
|
||||
(e-block
|
||||
(s-let
|
||||
(p-assign (ident "x"))
|
||||
(e-num (value "10")))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "x")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "y")))
|
||||
(e-closure
|
||||
(captures
|
||||
(capture (ident "x"))
|
||||
(capture (ident "y")))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "z")))
|
||||
(e-binop (op "add")
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "x")))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "y"))))
|
||||
(e-lookup-local
|
||||
(p-assign (ident "z")))))))))
|
||||
~~~
|
||||
# TYPES
|
||||
~~~clojure
|
||||
(expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
(expr (type "a -> (a -> a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
~~~
|
||||
|
|
|
|||
|
|
@ -5,21 +5,15 @@ type=mono
|
|||
~~~
|
||||
# SOURCE
|
||||
~~~roc
|
||||
{
|
||||
f = |x| x + 1
|
||||
f(41)
|
||||
}
|
||||
|x| x + 1
|
||||
~~~
|
||||
# MONO
|
||||
~~~roc
|
||||
42 : Dec
|
||||
#1({}) : a -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]
|
||||
~~~
|
||||
# FORMATTED
|
||||
~~~roc
|
||||
{
|
||||
f = |x| x + 1
|
||||
f(41)
|
||||
}
|
||||
NO CHANGE
|
||||
~~~
|
||||
# EXPECTED
|
||||
NIL
|
||||
|
|
@ -27,33 +21,29 @@ NIL
|
|||
NIL
|
||||
# TOKENS
|
||||
~~~zig
|
||||
OpenCurly,
|
||||
LowerIdent,OpAssign,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,Int,
|
||||
LowerIdent,NoSpaceOpenRound,Int,CloseRound,
|
||||
CloseCurly,
|
||||
OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,Int,
|
||||
EndOfFile,
|
||||
~~~
|
||||
# PARSE
|
||||
~~~clojure
|
||||
(e-block
|
||||
(statements
|
||||
(s-decl
|
||||
(p-ident (raw "f"))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "x")))
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "x"))
|
||||
(e-int (raw "1")))))
|
||||
(e-apply
|
||||
(e-ident (raw "f"))
|
||||
(e-int (raw "41")))))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-ident (raw "x")))
|
||||
(e-binop (op "+")
|
||||
(e-ident (raw "x"))
|
||||
(e-int (raw "1"))))
|
||||
~~~
|
||||
# CANONICALIZE
|
||||
~~~clojure
|
||||
(e-num (value "42"))
|
||||
(e-lambda
|
||||
(args
|
||||
(p-assign (ident "x")))
|
||||
(e-binop (op "add")
|
||||
(e-lookup-local
|
||||
(p-assign (ident "x")))
|
||||
(e-num (value "1"))))
|
||||
~~~
|
||||
# TYPES
|
||||
~~~clojure
|
||||
(expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
(expr (type "a -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))
|
||||
~~~
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue