Skip to content

Commit 9a37f57

Browse files
committed
Fix weird bug in error message
1 parent 5d31275 commit 9a37f57

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

examples/test.pf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ def
33
foo(i int) :
44
"foo"
55

6+
67
zort(t ... any?) :
7-
len(t)
8+
foo +
89

910
troz(i, j, k int) :
1011
"troz"

source/compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ NodeTypeSwitch:
356356
v, ok = env.GetVar(node.Value)
357357
}
358358
if !ok {
359-
cp.P.Throw("comp/ident/known", node.GetToken())
359+
cp.P.Throw("comp/ident/known", node.GetToken(), node.Value)
360360
break
361361
}
362362
if (v.access == GLOBAL_CONSTANT_PRIVATE || v.access == GLOBAL_VARIABLE_PRIVATE) && ac == REPL {

source/err/errorfile.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ var ErrorCreatorMap = map[string]ErrorCreator{
551551

552552
"comp/ident/known": {
553553
Message: func(tok *token.Token, args ...any) string {
554-
return "unknown identifier " + emph(tok.Literal)
554+
return "identifier " + emph(args[0].(string)) + " is undeclared"
555555
},
556556
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
557557
return "You don't seem to have declared that as a variable, function, constant, or anything else."
@@ -3466,6 +3466,9 @@ func blame(errors Errors, pos int, args ...string) string {
34663466
}
34673467

34683468
func emph(s any) string {
3469+
if t, ok := s.(string); ok {
3470+
s = strings.TrimSpace(t)
3471+
}
34693472
return fmt.Sprintf("'%v'", s)
34703473
}
34713474

0 commit comments

Comments
 (0)