Added a check for unused imports

This commit is contained in:
Eduard Urbach 2024-07-31 11:55:21 +02:00
parent 9ea99c97c4
commit 2d905c1ac0
Signed by: eduard
GPG key ID: 49226B848C78F6C8
14 changed files with 138 additions and 31 deletions

View file

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