mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
internal/cm: change error type from struct{string}
This is a temporary fix until cm@v0.2.2 is released, and package internal/cm and internal/wasi can be regenerated. See #4810 for more information.
This commit is contained in:
+9
-14
@@ -9,7 +9,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
|
||||
if len(cases) <= linearScanThreshold {
|
||||
return func(v *T, text []byte) error {
|
||||
if len(text) == 0 {
|
||||
return errEmpty
|
||||
return &emptyTextError{}
|
||||
}
|
||||
s := string(text)
|
||||
for i := 0; i < len(cases); i++ {
|
||||
@@ -18,7 +18,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errNoMatchingCase
|
||||
return &noMatchingCaseError{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
|
||||
|
||||
return func(v *T, text []byte) error {
|
||||
if len(text) == 0 {
|
||||
return errEmpty
|
||||
return &emptyTextError{}
|
||||
}
|
||||
c, ok := m[string(text)]
|
||||
if !ok {
|
||||
return errNoMatchingCase
|
||||
return &noMatchingCaseError{}
|
||||
}
|
||||
*v = c
|
||||
return nil
|
||||
@@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
|
||||
|
||||
const linearScanThreshold = 16
|
||||
|
||||
var (
|
||||
errEmpty = &stringError{"empty text"}
|
||||
errNoMatchingCase = &stringError{"no matching case"}
|
||||
)
|
||||
type emptyTextError struct{}
|
||||
|
||||
type stringError struct {
|
||||
err string
|
||||
}
|
||||
func (*emptyTextError) Error() string { return "empty text" }
|
||||
|
||||
func (err *stringError) Error() string {
|
||||
return err.err
|
||||
}
|
||||
type noMatchingCaseError struct{}
|
||||
|
||||
func (*noMatchingCaseError) Error() string { return "no matching case" }
|
||||
|
||||
Reference in New Issue
Block a user