Added a check for unused imports
This commit is contained in:
parent
9ea99c97c4
commit
2d905c1ac0
14 changed files with 138 additions and 31 deletions
|
@ -30,6 +30,20 @@ func (f *Function) CompileCall(root *expression.Expression) error {
|
|||
isSyscall := name == "syscall"
|
||||
|
||||
if !isSyscall {
|
||||
if pkg != f.File.Package {
|
||||
if f.File.Imports == nil {
|
||||
return errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
|
||||
}
|
||||
|
||||
imp, exists := f.File.Imports[pkg]
|
||||
|
||||
if !exists {
|
||||
return errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
|
||||
}
|
||||
|
||||
imp.Used = true
|
||||
}
|
||||
|
||||
tmp := strings.Builder{}
|
||||
tmp.WriteString(pkg)
|
||||
tmp.WriteString(".")
|
||||
|
@ -38,7 +52,7 @@ func (f *Function) CompileCall(root *expression.Expression) error {
|
|||
_, exists := f.Functions[fullName]
|
||||
|
||||
if !exists {
|
||||
return errors.New(&errors.UnknownFunction{Name: name}, f.File, root.Children[0].Token.Position)
|
||||
return errors.New(&errors.UnknownFunction{Name: name}, f.File, nameRoot.Token.Position)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue