From 5bea2d163d2f97c0ef57d9ebd72c640b2bd486c8 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Thu, 16 Mar 2023 15:07:41 +0100 Subject: [PATCH] Fix comments and remove commented-out code. --- crates/aiken-lang/src/ast.rs | 11 +++- crates/aiken-lang/src/tipo/error.rs | 2 +- crates/aiken-lang/src/tipo/pattern.rs | 90 --------------------------- 3 files changed, 9 insertions(+), 94 deletions(-) diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 2dee3bb8..4ed4abef 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -795,14 +795,20 @@ pub enum Pattern { }, /// The creation of a variable. - /// e.g. `assert [this_is_a_var, .._] = x` + /// e.g. `expect [this_is_a_var, .._] = x` + /// e.g. `let foo = 42` Var { location: Span, name: String, }, /// A name given to a sub-pattern using the `as` keyword. - /// e.g. `assert (1, [_, _] as the_list) = x` + /// + /// ```aiken + /// when foo is { + /// [_, _] as the_list -> ... + /// } + /// ``` Assign { name: String, location: Span, @@ -849,7 +855,6 @@ impl Pattern { | Pattern::List { location, .. } | Pattern::Discard { location, .. } | Pattern::Tuple { location, .. } - // | Pattern::Concatenate { location, .. } | Pattern::Constructor { location, .. } => *location, } } diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index ad802c5b..8ef7196d 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -254,7 +254,7 @@ You can use '{discard}' and numbers to distinguish between similar names. #[error("I found a discarded expression not bound to a variable.\n")] #[diagnostic(code("implicit_discard"))] #[diagnostic(help( - "A function can contain a sequence of expressions. However, any expression but the last one must be assign to a variable using the {keyword_let} keyword. If you really wish to discard an expression that is unused, you can assign it to '{discard}'.", + "A function can contain a sequence of expressions. However, any expression but the last one must be assigned to a variable using the {keyword_let} keyword. If you really wish to discard an expression that is unused, you can assign it to '{discard}'.", keyword_let = "let".if_supports_color(Stdout, |s| s.yellow()), discard = "_".if_supports_color(Stdout, |s| s.yellow()) ))] diff --git a/crates/aiken-lang/src/tipo/pattern.rs b/crates/aiken-lang/src/tipo/pattern.rs index 3f596dd3..ad3d5b1f 100644 --- a/crates/aiken-lang/src/tipo/pattern.rs +++ b/crates/aiken-lang/src/tipo/pattern.rs @@ -151,73 +151,6 @@ impl<'a, 'b> PatternTyper<'a, 'b> { Ok(typed_multi) } - // fn infer_pattern_bit_string( - // &mut self, - // mut segments: Vec, - // location: Span, - // ) -> Result { - // let last_segment = segments.pop(); - - // let mut typed_segments: Vec<_> = segments - // .into_iter() - // .map(|s| self.infer_pattern_segment(s, false)) - // .try_collect()?; - - // if let Some(s) = last_segment { - // let typed_last_segment = self.infer_pattern_segment(s, true)?; - // typed_segments.push(typed_last_segment) - // } - - // Ok(TypedPattern::BitString { - // location, - // segments: typed_segments, - // }) - // } - - // fn infer_pattern_segment( - // &mut self, - // segment: UntypedPatternBitStringSegment, - // is_last_segment: bool, - // ) -> Result { - // let UntypedPatternBitStringSegment { - // location, - // options, - // value, - // .. - // } = segment; - - // let options: Vec<_> = options - // .into_iter() - // .map(|o| infer_bit_string_segment_option(o, |value, typ| self.unify(value, typ))) - // .try_collect()?; - - // let segment_type = bit_string::type_options_for_pattern(&options, !is_last_segment) - // .map_err(|error| Error::BitStringSegmentError { - // error: error.error, - // location: error.location, - // })?; - - // let typ = { - // match value.deref() { - // Pattern::Var { .. } if segment_type == string() => { - // Err(Error::BitStringSegmentError { - // error: bit_string::ErrorType::VariableUtfSegmentInPattern, - // location, - // }) - // } - // _ => Ok(segment_type), - // } - // }?; - // let typed_value = self.unify(*value, typ.clone())?; - - // Ok(BitStringSegment { - // location, - // value: Box::new(typed_value), - // options, - // type_: typ, - // }) - // } - /// When we have an assignment or a case expression we unify the pattern with the /// inferred type of the subject in order to determine what variables to insert /// into the environment (or to detect a type error). @@ -236,29 +169,6 @@ impl<'a, 'b> PatternTyper<'a, 'b> { Ok(Pattern::Var { name, location }) } - // Pattern::Concatenate { - // location, - // left_location, - // right_location, - // left_side_string, - // right_side_assignment, - // } => { - // // The entire concatenate pattern must be a string - // self.environment.unify(tipo, string(), location)?; - - // // The right hand side may assign a variable, which is the suffix of the string - // if let AssignName::Variable(right) = &right_side_assignment { - // self.insert_variable(right.as_ref(), string(), right_location, location)?; - // }; - - // Ok(Pattern::Concatenate { - // location, - // left_location, - // right_location, - // left_side_string, - // right_side_assignment, - // }) - // } Pattern::Assign { name, pattern,