Skip to content

Commit

Permalink
core/expr: more precise feedback for type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Jan 2, 2024
1 parent b32ea1d commit 25ebfdf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/expr/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func castBoolPanic(in any, t *token.Token) bool {
case bool:
return v
default:
serror.Add(t, "Type error", "Incompatiable types %T and bool", in)
serror.Add(t, "Type error", "Expected value of type bool, got %s", token.TOKEN_NAME_MAP[t.Type])
serror.Panic()
}
// technically unreachable
Expand All @@ -24,7 +24,7 @@ func castFloatPanic(in any, t *token.Token) float64 {
case float64:
return v
default:
serror.Add(t, "Type error", "Incompatiable types %T and float64", in)
serror.Add(t, "Type error", "Expected value of type float, got %s", token.TOKEN_NAME_MAP[t.Type])
serror.Panic()
}
// technically unreachable
Expand All @@ -37,7 +37,7 @@ func castPanicIfNotType[T any](in any, t *token.Token) T {
val, ok := in.(T)
if !ok {
var e T
serror.Add(t, "Type error", "Incompatiable types %T and %T", in, e)
serror.Add(t, "Type error", "Expected value of type %T, got %T", e, in)
serror.Panic()
}
return val
Expand Down

0 comments on commit 25ebfdf

Please sign in to comment.