for: check for redefinitions

pull/3091/head
Alexander Medvednikov 2019-12-14 19:58:55 +03:00
parent be2b5698c5
commit 2e23592264
3 changed files with 15 additions and 6 deletions

View File

@ -122,12 +122,12 @@ pub fn run_repl() []string {
} }
was_func := r.in_func was_func := r.in_func
if r.checks() { if r.checks() {
for line in r.line.split('\n') { for rline in r.line.split('\n') {
if r.in_func || was_func { if r.in_func || was_func {
r.functions << line r.functions << rline
} }
else { else {
r.temp_lines << line r.temp_lines << rline
} }
} }
if r.indent > 0 { if r.indent > 0 {

View File

@ -247,7 +247,7 @@ struct Article {
text string text string
} }
pub fn (app & App) find_all_articles() []Article { pub fn (app &App) find_all_articles() []Article {
db := app.db db := app.db
articles := db.select from Article articles := db.select from Article
return articles return articles
@ -314,8 +314,8 @@ article := app.retrieve_article(10) or {
``` ```
> Temporary variables like `db := app.db` are a temporary limitation in the > `db := app.db` is a temporary limitation in the
V ORM, soon they will not be needed. V ORM, soon this will not be needed.
To be continued on Dec 14... To be continued on Dec 14...

View File

@ -103,6 +103,9 @@ fn (p mut Parser) for_st() {
} }
// Register temp vars // Register temp vars
if i != '_' { if i != '_' {
if p.known_var(i) {
p.error('redefinition of `$i`')
}
p.register_var(Var { p.register_var(Var {
name: i name: i
typ: i_var_type typ: i_var_type
@ -111,6 +114,9 @@ fn (p mut Parser) for_st() {
}) })
} }
if val != '_' { if val != '_' {
if p.known_var(val) {
p.error('redefinition of `$val`')
}
p.register_var(Var { p.register_var(Var {
name: val name: val
typ: typ typ: typ
@ -182,6 +188,9 @@ fn (p mut Parser) for_st() {
// println('for typ=$typ vartyp=$var_typ') // println('for typ=$typ vartyp=$var_typ')
// Register temp var // Register temp var
if val != '_' { if val != '_' {
if p.known_var(val) {
p.error('redefinition of `$val`')
}
p.register_var(Var { p.register_var(Var {
name: val name: val
typ: typ typ: typ