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
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 {

View File

@ -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...

View File

@ -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