Assert that all expressions have types
This is a bit of paranoia, however, an invariant of the typechecker is that, after the final pass, all expression nodes are assigned a type. This assertion checks that this is true.
This commit is contained in:
parent
9fe2f28e7b
commit
d907e358ad
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/marapongo/mu/pkg/compiler/errors"
|
||||
"github.com/marapongo/mu/pkg/compiler/symbols"
|
||||
"github.com/marapongo/mu/pkg/compiler/types"
|
||||
"github.com/marapongo/mu/pkg/util/contract"
|
||||
)
|
||||
|
||||
// bindFunctionBody binds a function body, including a scope, its parameters, and its expressions and statements.
|
||||
|
@ -162,6 +163,10 @@ func (a *astBinder) After(node ast.Node) {
|
|||
// TODO: check that there's at least one!
|
||||
a.b.registerExprType(n, a.b.requireExprType(n.Expressions[len(n.Expressions)-1]))
|
||||
}
|
||||
|
||||
// Ensure that all expression types resulted in a type registration.
|
||||
expr, isExpr := node.(ast.Expression)
|
||||
contract.Assert(!isExpr || a.b.requireExprType(expr) != nil)
|
||||
}
|
||||
|
||||
func (a *astBinder) checkExprType(expr ast.Expression, expect symbols.Type) bool {
|
||||
|
|
Loading…
Reference in a new issue