vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.88k stars 2.17k forks source link

redefinition/redeclare inside a module #1857

Closed esquerbatua closed 5 years ago

esquerbatua commented 5 years ago

V version: 0.1.18 OS: Ubuntu 18.04

What did you do? v -lib constant/

What did you expect to see? Compilation sucess

What did you see instead? /home/x/test/constant/const.v:5:1: redefinition of constant.URL

Code:

constant/constant.v

module constant

import json
import http

const (
        URL = 'google.es'
)

struct Test {
        name string
}

pub fn main() {
        println(URL + '/')
        test := Test{'one'}
        println(test.name)
}

Referenced issues: #749 #456

Henrixounez commented 5 years ago

Please use v build module constant/ as per this https://github.com/vlang/v/issues/1736#issuecomment-524615001 An update on the help could be helpfull though.

teggotic commented 5 years ago

I'm closing this issue because v build module constant/ is working for code in issue. Thank you @Henrixounez.

esquerbatua commented 5 years ago

Sorry @Danil-Lapirow I get working using

v build module constant/

, but I get other time the error importing some library, like json or http

here is the code:

module constant

import json
import http

const (
        URL = 'google.es'
)

struct Test {
        name string
}

pub fn main() {
        println(URL + '/')
        test := Test{'one'}
        println(test.name)
}
esquerbatua commented 5 years ago

Sorry @Henrixounez if you can review the last comment, the error remains. Unless there is some other way to execute the compilation. Thank you!

Henrixounez commented 5 years ago

Thanks @esquerbatua , indeed the way it worked was changed and v build constant/ didn't worked but v build constant would have.

esquerbatua commented 5 years ago

Sorry, but the error remains @Henrixounez @medvednikov

constant/const.v:8:1: redefinition of constant.URL

Henrixounez commented 5 years ago

Have you updated your v ?

esquerbatua commented 5 years ago

Yes, and I get the same error with 'v build constant/' and 'v build constant', probably the error it's caused by the fix of the struct order?

Henrixounez commented 5 years ago

I have copied your code and put in in ./constant/constant.v then run v build constant and have no errors.

esquerbatua commented 5 years ago

@Henrixounez I think he has had a misunderstanding (sorry about that), you tested the code in the first comment, and that with v build constant yes it works (now I edit the first comment so there are no misunderstanding errors). The problem is when you put some import in the file, like in this comment

Henrixounez commented 5 years ago

Yes, i have tested this one but have no problems.

esquerbatua commented 5 years ago

A lot of thanks! All working.