Skip to content

Commit c7b3b54

Browse files
committed
Catch undefined variables and functions before compilation
Rugo now reports undefined variable and function errors instantly instead of waiting for the Go compiler to fail. Error messages include the exact source file and line number. Examples of errors now caught early: script.rugo:3: undefined variable 'xyz' script.rugo:5: undefined function helper.nonexistent This also validates namespaced calls (ns.func()) against the actual functions exported by required modules, stdlib modules, and Go bridge packages.
1 parent ec1bc22 commit c7b3b54

7 files changed

Lines changed: 805 additions & 18 deletions

File tree

ast/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/rubiojr/rugo/parser"
1212
)
1313

14-
//go:embed nodes.go walker.go preprocess.go parse.go lower.go transform.go factory.go implicit_return.go
14+
//go:embed check.go nodes.go walker.go preprocess.go parse.go lower.go transform.go factory.go implicit_return.go
1515
var Sources embed.FS
1616

1717
// goModTemplate is the go.mod for the cached AST module.

ast/check.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ast
2+
3+
// Check validates an AST without modifying it.
4+
type Check interface {
5+
Name() string
6+
Check(prog *Program) error
7+
}
8+
9+
// CheckChain runs checks in order, stopping at the first error.
10+
type CheckChain []Check
11+
12+
// Run executes each check in sequence. Returns nil if all pass.
13+
func (cc CheckChain) Run(prog *Program) error {
14+
for _, c := range cc {
15+
if err := c.Check(prog); err != nil {
16+
return err
17+
}
18+
}
19+
return nil
20+
}

0 commit comments

Comments
 (0)