Skip to content

Commit

Permalink
lang: ast: Expr Param and Poly should not have values
Browse files Browse the repository at this point in the history
Sometimes a recursive call through ExprVar's Value method would hit one
of these and return (nil, nil) which would throw off things.
  • Loading branch information
purpleidea committed Dec 18, 2023
1 parent 6a6546d commit c333cb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lang/ast/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8682,7 +8682,7 @@ func (obj *ExprParam) SetValue(value types.Value) error {
// usually only be valid once the engine has run and values have been produced.
// This might get called speculatively (early) during unification to learn more.
func (obj *ExprParam) Value() (types.Value, error) {
return nil, nil
return nil, fmt.Errorf("no value for ExprParam")
}

// ExprPoly is a polymorphic expression that is a definition that can be used in
Expand Down Expand Up @@ -8799,7 +8799,7 @@ func (obj *ExprPoly) SetValue(value types.Value) error {
// usually only be valid once the engine has run and values have been produced.
// This might get called speculatively (early) during unification to learn more.
func (obj *ExprPoly) Value() (types.Value, error) {
return nil, nil
return nil, fmt.Errorf("no value for ExprPoly")
}

// ExprIf represents an if expression which *must* have both branches, and which
Expand Down
12 changes: 12 additions & 0 deletions lang/interpret_test/TestAstFunc2/scope-lambda-printf.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- main.mcl --
import "fmt"
$format = "%d" # should get ignored
$fn = func($format) {
fmt.printf($format, 42)
}
test $fn("%s") {}
# should error at unification if possible, otherwise at runtime
# TODO: I would expect that if the "%s" and "%d" swapped, that speculatively we
# would be able to run this at compile time and know the result statically.
-- OUTPUT --
# err: errStream: func `printf@??????????` stopped before it was loaded: base kind does not match (Str != Int)

0 comments on commit c333cb5

Please sign in to comment.