aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2024-02-19 15:57:30 +0100
committerGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2024-02-19 15:57:30 +0100
commit2ea5305e81746bb60eca30d2171a5cc6b04ada4b (patch)
treeacc3a93825616a147398c3ea4bda9c6774480828
parent3c84774b5fb116203879b497e1fe4aeac1e25471 (diff)
downloadlustre-2ea5305e81746bb60eca30d2171a5cc6b04ada4b.tar.gz
lustre-2ea5305e81746bb60eca30d2171a5cc6b04ada4b.zip
:bug: Fix decoding for tuples and function arguments
-rw-r--r--src/lustre/cli/project.gleam16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/lustre/cli/project.gleam b/src/lustre/cli/project.gleam
index 2698113..68b5801 100644
--- a/src/lustre/cli/project.gleam
+++ b/src/lustre/cli/project.gleam
@@ -35,6 +35,7 @@ pub type Type {
Named(name: String, package: String, module: String, parameters: List(Type))
Variable(id: Int)
Fn(parameters: List(Type), return: Type)
+ Tuple(elements: List(Type))
}
// COMMANDS --------------------------------------------------------------------
@@ -153,7 +154,7 @@ fn decode_module(dyn: Dynamic) -> Result(Module, List(DecodeError)) {
fn decode_function(dyn: Dynamic) -> Result(Function, List(DecodeError)) {
dynamic.decode2(
Function,
- dynamic.field("parameters", dynamic.list(decode_type)),
+ dynamic.field("parameters", dynamic.list(decode_labelled_argument)),
dynamic.field("return", decode_type),
)(dyn)
}
@@ -165,6 +166,7 @@ fn decode_type(dyn: Dynamic) -> Result(Type, List(DecodeError)) {
"named" -> decode_named_type(dyn)
"variable" -> decode_variable_type(dyn)
"fn" -> decode_fn_type(dyn)
+ "tuple" -> decode_tuple_type(dyn)
_ ->
Error([
@@ -196,3 +198,15 @@ fn decode_fn_type(dyn: Dynamic) -> Result(Type, List(DecodeError)) {
dynamic.field("return", decode_type),
)(dyn)
}
+
+fn decode_tuple_type(dyn: Dynamic) -> Result(Type, List(DecodeError)) {
+ dynamic.decode1(Tuple, dynamic.field("elements", dynamic.list(decode_type)))(
+ dyn,
+ )
+}
+
+fn decode_labelled_argument(dyn: Dynamic) -> Result(Type, List(DecodeError)) {
+ // In this case we don't really care about the label, so we're just ignoring
+ // it and returning the argument's type.
+ dynamic.field("type", decode_type)(dyn)
+}