Skip to content

Commit

Permalink
Fix weird bug in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Jan 31, 2025
1 parent 5d31275 commit 9a37f57
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/test.pf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ def
foo(i int) :
"foo"


zort(t ... any?) :
len(t)
foo +

troz(i, j, k int) :
"troz"
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ NodeTypeSwitch:
v, ok = env.GetVar(node.Value)
}
if !ok {
cp.P.Throw("comp/ident/known", node.GetToken())
cp.P.Throw("comp/ident/known", node.GetToken(), node.Value)
break
}
if (v.access == GLOBAL_CONSTANT_PRIVATE || v.access == GLOBAL_VARIABLE_PRIVATE) && ac == REPL {
Expand Down
5 changes: 4 additions & 1 deletion source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ var ErrorCreatorMap = map[string]ErrorCreator{

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

func emph(s any) string {
if t, ok := s.(string); ok {
s = strings.TrimSpace(t)
}
return fmt.Sprintf("'%v'", s)
}

Expand Down

0 comments on commit 9a37f57

Please sign in to comment.