internal/rosa/azalea: store the zero value for nil
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 2m48s
Test / Hakurei (push) Successful in 4m42s
Test / Sandbox (race detector) (push) Successful in 5m54s
Test / Hakurei (race detector) (push) Successful in 7m1s
Test / ShareFS (push) Successful in 7m13s
Test / Flake checks (push) Successful in 1m11s
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 2m48s
Test / Hakurei (push) Successful in 4m42s
Test / Sandbox (race detector) (push) Successful in 5m54s
Test / Hakurei (race detector) (push) Successful in 7m1s
Test / ShareFS (push) Successful in 7m13s
Test / Flake checks (push) Successful in 1m11s
This is not final, but the behaviour is acceptable for now. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// Value are types supported by the language.
|
// Value are types supported by the language.
|
||||||
type Value interface {
|
type Value interface {
|
||||||
bool | int64 | string | []string | []int64 | [][2]string
|
bool | int64 | string | []string | []int64 | [][2]string | Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -50,6 +50,11 @@ func (args FArgs) Apply(v map[unique.Handle[Ident]]any) error {
|
|||||||
}
|
}
|
||||||
return UndefinedError(arg.K.Value())
|
return UndefinedError(arg.K.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if arg.V == (Nil{}) {
|
||||||
|
reflect.ValueOf(r).Elem().SetZero()
|
||||||
|
continue
|
||||||
|
}
|
||||||
err := storeE(r, arg.V)
|
err := storeE(r, arg.V)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -115,7 +120,7 @@ func (e TypeError) Is(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// storeE is a convenience function to set the value of a result pointer.
|
// storeE is a convenience function to set the value of a result pointer.
|
||||||
func storeE(rp any, r any) error {
|
func storeE(rp, r any) error {
|
||||||
pv := reflect.ValueOf(rp).Elem()
|
pv := reflect.ValueOf(rp).Elem()
|
||||||
v := reflect.ValueOf(r)
|
v := reflect.ValueOf(r)
|
||||||
pt, vt := pv.Type(), v.Type()
|
pt, vt := pv.Type(), v.Type()
|
||||||
@@ -166,6 +171,9 @@ var (
|
|||||||
ErrInvalidSpecial = errors.New("special must not be common or bound to scope")
|
ErrInvalidSpecial = errors.New("special must not be common or bound to scope")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Nil represents an untyped nil.
|
||||||
|
type Nil struct{}
|
||||||
|
|
||||||
// evaluateAny implements [Evaluate].
|
// evaluateAny implements [Evaluate].
|
||||||
func evaluateAny(d PF, s []Frame, expr, rp any) bool {
|
func evaluateAny(d PF, s []Frame, expr, rp any) bool {
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -226,6 +234,9 @@ func evaluateAny(d PF, s []Frame, expr, rp any) bool {
|
|||||||
case "false":
|
case "false":
|
||||||
store(rp, false)
|
store(rp, false)
|
||||||
return true
|
return true
|
||||||
|
case "nil":
|
||||||
|
store(rp, Nil{})
|
||||||
|
return true
|
||||||
default:
|
default:
|
||||||
return evaluateAny(d, s, v, rp)
|
return evaluateAny(d, s, v, rp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,15 +100,19 @@ func TestEvaluate(t *testing.T) {
|
|||||||
Err: UndefinedError("f"),
|
Err: UndefinedError("f"),
|
||||||
}},
|
}},
|
||||||
|
|
||||||
{"error wrap deep", `f { v = nil; }`, makeStackCheck(func(
|
{"error wrap deep", `f { v = nonexistent; }`, makeStackCheck(func(
|
||||||
FArgs,
|
FArgs,
|
||||||
) (any, error) {
|
) (any, error) {
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}), "", EvaluationError{
|
}), "", EvaluationError{
|
||||||
Expr: Ident("nil"),
|
Expr: Ident("nonexistent"),
|
||||||
Err: UndefinedError("nil"),
|
Err: UndefinedError("nonexistent"),
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
{"nil", `f { v = nil; }`, checkArgs(FArgs{
|
||||||
|
{K: unique.Make(Ident("v")), V: Nil{}},
|
||||||
|
}), "\xfd", nil},
|
||||||
|
|
||||||
{"common inputs", `package name { inputs, v = []; }`, nil, "", EvaluationError{
|
{"common inputs", `package name { inputs, v = []; }`, nil, "", EvaluationError{
|
||||||
Expr: Func{
|
Expr: Func{
|
||||||
Ident: Ident("name"),
|
Ident: Ident("name"),
|
||||||
|
|||||||
Reference in New Issue
Block a user