From ca51aa52bdf5528268fb2f66c2d4f21119d34668 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 3 Jun 2015 19:39:48 -0400 Subject: [PATCH] frontend: warn useless `do` blocks Signed-off-by: Jean Privat --- src/frontend/simple_misc_analysis.nit | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/frontend/simple_misc_analysis.nit b/src/frontend/simple_misc_analysis.nit index 885d794..f61b10a 100644 --- a/src/frontend/simple_misc_analysis.nit +++ b/src/frontend/simple_misc_analysis.nit @@ -65,6 +65,14 @@ private class SimpleMiscVisitor do toolcontext.warning(node.hot_location, tag, msg) end + + # Issue a warning if `sub` is a standalone `do` block. + fun check_do_expr(sub: nullable AExpr) + do + if sub isa ADoExpr then + warning(sub, "useless-do", "Warning: superfluous `do` block.") + end + end end @@ -143,6 +151,21 @@ redef class AWhileExpr else n_expr.warn_parentheses(v) end + v.check_do_expr(n_block) + end +end + +redef class ADoExpr + redef fun after_simple_misc(v) + do + v.check_do_expr(n_block) + end +end + +redef class ALoopExpr + redef fun after_simple_misc(v) + do + v.check_do_expr(n_block) end end @@ -150,6 +173,14 @@ redef class AForExpr redef fun after_simple_misc(v) do n_expr.warn_parentheses(v) + v.check_do_expr(n_block) + end +end + +redef class AWithExpr + redef fun after_simple_misc(v) + do + v.check_do_expr(n_block) end end -- 1.7.9.5