diff --git a/internal/compiler/analyzer/main_pkg.go b/internal/compiler/analyzer/main_pkg.go index 69a0d14c..f867bde5 100644 --- a/internal/compiler/analyzer/main_pkg.go +++ b/internal/compiler/analyzer/main_pkg.go @@ -11,6 +11,7 @@ var ( ErrMainEntityNotFound = errors.New("entity main is not found") ErrMainEntityIsNotComponent = errors.New("main entity is not a component") ErrMainEntityExported = errors.New("main entity is exported") + ErrMainPkgExports = errors.New("main pkg must not have exported entities") ) func (a Analyzer) mainSpecificPkgValidation(pkg src.Package, pkgs map[string]src.Package) error { @@ -31,5 +32,14 @@ func (a Analyzer) mainSpecificPkgValidation(pkg src.Package, pkgs map[string]src return fmt.Errorf("analyze main component: %w", err) } + if err := pkg.Entities(func(entity src.Entity, entityName, fileName string) error { // FIXME will conflict with general validation + if entity.Exported { + return fmt.Errorf("%w: file %v, entity %v", ErrMainPkgExports, fileName, entityName) + } + return nil + }); err != nil { + return err + } + return nil } diff --git a/internal/compiler/src/src.go b/internal/compiler/src/src.go index 3dba88ab..9978218d 100644 --- a/internal/compiler/src/src.go +++ b/internal/compiler/src/src.go @@ -40,6 +40,17 @@ func (p Package) Entity(name string) (Entity, bool) { return Entity{}, false } +func (p Package) Entities(f func(entity Entity, entityName string, fileName string) error) error { + for fileName, file := range p { + for entityName, entity := range file.Entities { + if err := f(entity, entityName, fileName); err != nil { + return err + } + } + } + return nil +} + type File struct { Imports map[string]string Entities map[string]Entity