From b62323b06ae94939e3133a49240e60c1af4dbd89 Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Wed, 28 Aug 2024 15:26:52 -0300 Subject: [PATCH] Fix empty tuples --- README.md | 4 ++-- src/compiler/internal/generator/expressions.gleam | 2 +- test/compiler/case_test.gleam | 6 +++--- test/compiler/expression_test.gleam | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 694a1db..4cec0c6 100644 --- a/README.md +++ b/README.md @@ -146,15 +146,15 @@ are ) in the codebase, as of the last time that I updated this list. ### Some other things I know are missing -- empty tuples are probably broken - - (EASY) I used parens instead of a `,` like a total python NOOB - no let assert - (EASY) const definitions aren't supported yet (module.constants) - type aliases aren't supported yet (module.type_aliases) +- macabre_stdlib only has `io.println` - Not doing anything to avoid collision between gleam identifiers with python keywords - Especially: shadowed variable names behave differently if used in closures - glance itself doesn't support comments, so these are stripped out of the compiled code - glance doesn't have (much of) a typechecker +- the standard gleam LSP chokes on the fact that I don't have dependencies in hex - not currently generating python type hints (e.g. function arguments and return types), but gleam gives us that info so may as well use it - No Result custom type yet (I thought this needed to be in the prelude, but I don't see any result-specific syntax anywhere) diff --git a/src/compiler/internal/generator/expressions.gleam b/src/compiler/internal/generator/expressions.gleam index 0d96d48..a39997c 100644 --- a/src/compiler/internal/generator/expressions.gleam +++ b/src/compiler/internal/generator/expressions.gleam @@ -57,7 +57,7 @@ pub fn generate_expression(expression: python.Expression) -> StringBuilder { expressions |> internal.generate_plural(generate_expression, ", "), ) - |> string_builder.append(")") + |> string_builder.append(",)") python.TupleIndex(expression, index) -> generate_expression(expression) diff --git a/test/compiler/case_test.gleam b/test/compiler/case_test.gleam index af58994..bd59ac7 100644 --- a/test/compiler/case_test.gleam +++ b/test/compiler/case_test.gleam @@ -108,7 +108,7 @@ def main(): match _case_subject: case (1, 2): return \"one\" - return _fn_case_0((1, 2))", + return _fn_case_0((1, 2,))", ) } @@ -152,7 +152,7 @@ def main(): match _case_subject: case (1, x): return x + 50 - return _fn_case_0((1, 2))", + return _fn_case_0((1, 2,))", ) } @@ -196,7 +196,7 @@ def main(): match _case_subject: case (1, 2) | (2, 3): return 5 - return _fn_case_0((1, 2))", + return _fn_case_0((1, 2,))", ) } diff --git a/test/compiler/expression_test.gleam b/test/compiler/expression_test.gleam index 5e81aa0..1e954fa 100644 --- a/test/compiler/expression_test.gleam +++ b/test/compiler/expression_test.gleam @@ -58,7 +58,7 @@ pub fn tuple_expression_test() { "from gleam_builtins import * def main(): - return (42, 12.5, \"foo\")", + return (42, 12.5, \"foo\",)", ) } @@ -255,7 +255,7 @@ pub fn tuple_index_test() { "from gleam_builtins import * def main(): - return (42, 12.5, \"foo\")[1]", + return (42, 12.5, \"foo\",)[1]", ) } @@ -675,7 +675,7 @@ def main(): pass def _fn_def_1(c, d): pass - foo = (_fn_def_0, _fn_def_1)", + foo = (_fn_def_0, _fn_def_1,)", ) }