From 2e23592264ccca2031b1b4fc245058fb2ebad204 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 14 Dec 2019 19:58:55 +0300 Subject: [PATCH] for: check for redefinitions --- tools/vrepl.v | 6 +++--- tutorials/building-a-simple-web-blog-with-vweb.md | 6 +++--- vlib/compiler/for.v | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/vrepl.v b/tools/vrepl.v index 3b445aa9d2..b1b8c02e0b 100644 --- a/tools/vrepl.v +++ b/tools/vrepl.v @@ -122,12 +122,12 @@ pub fn run_repl() []string { } was_func := r.in_func if r.checks() { - for line in r.line.split('\n') { + for rline in r.line.split('\n') { if r.in_func || was_func { - r.functions << line + r.functions << rline } else { - r.temp_lines << line + r.temp_lines << rline } } if r.indent > 0 { diff --git a/tutorials/building-a-simple-web-blog-with-vweb.md b/tutorials/building-a-simple-web-blog-with-vweb.md index 56bd27a35f..58431fd3c3 100644 --- a/tutorials/building-a-simple-web-blog-with-vweb.md +++ b/tutorials/building-a-simple-web-blog-with-vweb.md @@ -247,7 +247,7 @@ struct Article { text string } -pub fn (app & App) find_all_articles() []Article { +pub fn (app &App) find_all_articles() []Article { db := app.db articles := db.select from Article return articles @@ -314,8 +314,8 @@ article := app.retrieve_article(10) or { ``` -> Temporary variables like `db := app.db` are a temporary limitation in the -V ORM, soon they will not be needed. +> `db := app.db` is a temporary limitation in the +V ORM, soon this will not be needed. To be continued on Dec 14... diff --git a/vlib/compiler/for.v b/vlib/compiler/for.v index fc9a1f0633..5badadfaf2 100644 --- a/vlib/compiler/for.v +++ b/vlib/compiler/for.v @@ -103,6 +103,9 @@ fn (p mut Parser) for_st() { } // Register temp vars if i != '_' { + if p.known_var(i) { + p.error('redefinition of `$i`') + } p.register_var(Var { name: i typ: i_var_type @@ -111,6 +114,9 @@ fn (p mut Parser) for_st() { }) } if val != '_' { + if p.known_var(val) { + p.error('redefinition of `$val`') + } p.register_var(Var { name: val typ: typ @@ -182,6 +188,9 @@ fn (p mut Parser) for_st() { // println('for typ=$typ vartyp=$var_typ') // Register temp var if val != '_' { + if p.known_var(val) { + p.error('redefinition of `$val`') + } p.register_var(Var { name: val typ: typ