From a6057319a9af1cb2bf315a9d30035f6319ec2a55 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 12 Mar 2025 00:23:20 -0400 Subject: [PATCH] lang: Make scope error messages be more consistent --- lang/ast/structs.go | 4 ++-- lang/interpret_test/TestAstFunc1/graph8.txtar | 2 +- .../interpret_test/TestAstFunc2/class-include-as-class0.txtar | 3 ++- lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar | 2 +- lang/interpret_test/TestAstFunc2/import-scope-classes4.txtar | 3 ++- .../interpret_test/TestAstFunc2/import-scope-vars2-fail.txtar | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lang/ast/structs.go b/lang/ast/structs.go index e7abaf64..03d172ad 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -9768,7 +9768,7 @@ func (obj *ExprCall) SetScope(scope *interfaces.Scope, sctx map[string]interface if obj.data.Debug || true { // TODO: leave this on permanently? lambdaScopeFeedback(obj.scope, obj.data.Logf) } - return fmt.Errorf("func `%s` does not exist in this scope", prefixedName) + return fmt.Errorf("lambda `$%s` does not exist in this scope", prefixedName) } target = f } @@ -10462,7 +10462,7 @@ func (obj *ExprVar) SetScope(scope *interfaces.Scope, sctx map[string]interfaces if obj.data.Debug || true { // TODO: leave this on permanently? variableScopeFeedback(obj.scope, obj.data.Logf) } - return fmt.Errorf("variable %s not in scope", obj.Name) + return fmt.Errorf("var `$%s` does not exist in this scope", obj.Name) } obj.scope.Variables[obj.Name] = target diff --git a/lang/interpret_test/TestAstFunc1/graph8.txtar b/lang/interpret_test/TestAstFunc1/graph8.txtar index e0766e85..a0d78a2e 100644 --- a/lang/interpret_test/TestAstFunc1/graph8.txtar +++ b/lang/interpret_test/TestAstFunc1/graph8.txtar @@ -6,4 +6,4 @@ if true { $b = true } -- OUTPUT -- -# err: errSetScope: variable b not in scope +# err: errSetScope: var `$b` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc2/class-include-as-class0.txtar b/lang/interpret_test/TestAstFunc2/class-include-as-class0.txtar index 1e810192..2a9c467e 100644 --- a/lang/interpret_test/TestAstFunc2/class-include-as-class0.txtar +++ b/lang/interpret_test/TestAstFunc2/class-include-as-class0.txtar @@ -16,7 +16,8 @@ panic($i0.x != "goodbye") panic($i1.y != "hello") # the really tricky case -# XXX: works atm, but not supported for now: could not set scope: variable i0.y not in scope +# XXX: works atm, but not supported for now, error is: +# could not set scope: var `$i0.y` does not exist in this scope # We currently re-export anything in the parent scope as available from our # current child scope, which makes this variable visible. Unfortunately, it does # not have the correct dependency (edge) present in the Ordering system, so it diff --git a/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar b/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar index 1245a085..200eaab5 100644 --- a/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar +++ b/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar @@ -7,4 +7,4 @@ $f = func($x) { $name = $f("foo") test "${name}" {} -- OUTPUT -- -# err: errSetScope: variable x not in scope +# err: errSetScope: var `$x` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc2/import-scope-classes4.txtar b/lang/interpret_test/TestAstFunc2/import-scope-classes4.txtar index 4c782676..6c92b567 100644 --- a/lang/interpret_test/TestAstFunc2/import-scope-classes4.txtar +++ b/lang/interpret_test/TestAstFunc2/import-scope-classes4.txtar @@ -14,7 +14,8 @@ test "${f1.z}" {} test "${f1.x1}" {} # the really tricky case -# XXX: works atm, but not supported for now: could not set scope: variable f1.x2 not in scope +# XXX: works atm, but not supported for now, error is: +# could not set scope: var `$f1.x2` does not exist in this scope # We currently re-export anything in the parent scope as available from our # current child scope, which makes this variable visible. Unfortunately, it does # not have the correct dependency (edge) present in the Ordering system, so it diff --git a/lang/interpret_test/TestAstFunc2/import-scope-vars2-fail.txtar b/lang/interpret_test/TestAstFunc2/import-scope-vars2-fail.txtar index 4c4b69a1..0934c9f8 100644 --- a/lang/interpret_test/TestAstFunc2/import-scope-vars2-fail.txtar +++ b/lang/interpret_test/TestAstFunc2/import-scope-vars2-fail.txtar @@ -11,4 +11,4 @@ $x = "this is x.mcl" import "x.mcl" as f $y = $f.x + " and this is y.mcl" -- OUTPUT -- -# err: errSetScope: variable g.x not in scope +# err: errSetScope: var `$g.x` does not exist in this scope