From bd767c07cb0506943a26c22e8d1c46e97f6f4ed3 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Fri, 17 May 2019 22:36:16 +0200 Subject: [PATCH] fix(check): Propagate metadata through parens --- check/src/metadata.rs | 3 ++- check/tests/metadata.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/check/src/metadata.rs b/check/src/metadata.rs index d059552897..f4593cb326 100644 --- a/check/src/metadata.rs +++ b/check/src/metadata.rs @@ -65,7 +65,7 @@ impl ArcMetadata for MaybeMetadata { } } -#[derive(Clone)] +#[derive(Clone, Debug)] enum MaybeMetadata { Empty, Data(Arc), @@ -371,6 +371,7 @@ pub fn metadata( Expr::MacroExpansion { ref replacement, .. } => self.metadata_expr(replacement), + Expr::Tuple { ref elems, .. } if elems.len() == 1 => self.metadata_expr(&elems[0]), _ => { ast::walk_expr(self, expr); Default::default() diff --git a/check/tests/metadata.rs b/check/tests/metadata.rs index 73c841d218..1984ed9275 100644 --- a/check/tests/metadata.rs +++ b/check/tests/metadata.rs @@ -116,6 +116,31 @@ type Test = Int ); } +#[test] +fn propagate_metadata_parens() { + let _ = env_logger::try_init(); + + let text = r#" +/// The identity function +let id x = x +id +"#; + let (mut expr, result) = support::typecheck_expr(text); + + assert!(result.is_ok(), "{}", result.unwrap_err()); + + let metadata = metadata(&MockEnv, &mut expr); + assert_eq!( + metadata, + Metadata { + definition: Some(intern("id:32")), + comment: Some(line_comment("The identity function")), + args: vec![Argument::explicit(intern("x:35"))], + ..Metadata::default() + } + ); +} + #[test] fn propagate_metadata_record_field_comment() { let _ = env_logger::try_init();