From e9d0642b29ed3facfa1c0c2ad6029629ca95af1b Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 4 Dec 2022 11:44:13 +0900 Subject: [PATCH] Fix a desugaring bug --- compiler/erg_parser/ast.rs | 8 +++++++- compiler/erg_parser/desugar.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/erg_parser/ast.rs b/compiler/erg_parser/ast.rs index 2097ba8d..af8ecc7c 100644 --- a/compiler/erg_parser/ast.rs +++ b/compiler/erg_parser/ast.rs @@ -1979,7 +1979,13 @@ impl fmt::Display for TypeSpec { } write!(f, "}}") } - Self::Enum(elems) => write!(f, "{{{elems}}}"), + Self::Enum(elems) => { + write!(f, "{{")?; + for elem in elems.pos_args() { + write!(f, "{}, ", elem.expr)?; + } + write!(f, "}}") + } Self::Interval { op, lhs, rhs } => write!(f, "{lhs}{}{rhs}", op.inspect()), Self::Subr(s) => write!(f, "{s}"), Self::TypeApp { spec, args } => write!(f, "{spec}{args}"), diff --git a/compiler/erg_parser/desugar.rs b/compiler/erg_parser/desugar.rs index e7adc2e0..7548998c 100644 --- a/compiler/erg_parser/desugar.rs +++ b/compiler/erg_parser/desugar.rs @@ -992,6 +992,17 @@ impl Desugarer { insertion_idx += 1; insertion_idx } + ParamPattern::Lit(l) => { + let lit = l.clone(); + sig.pat = ParamPattern::Discard(Token::new( + TokenKind::UBar, + "_", + l.ln_begin().unwrap(), + l.col_begin().unwrap(), + )); + sig.t_spec = Some(TypeSpecWithOp::new(COLON, TypeSpec::enum_t_spec(vec![lit]))); + insertion_idx + } _ => insertion_idx, } }