mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 02:33:28 +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 {
|
if len(cases) <= linearScanThreshold {
|
||||||
return func(v *T, text []byte) error {
|
return func(v *T, text []byte) error {
|
||||||
if len(text) == 0 {
|
if len(text) == 0 {
|
||||||
return errEmpty
|
return &emptyTextError{}
|
||||||
}
|
}
|
||||||
s := string(text)
|
s := string(text)
|
||||||
for i := 0; i < len(cases); i++ {
|
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 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 {
|
return func(v *T, text []byte) error {
|
||||||
if len(text) == 0 {
|
if len(text) == 0 {
|
||||||
return errEmpty
|
return &emptyTextError{}
|
||||||
}
|
}
|
||||||
c, ok := m[string(text)]
|
c, ok := m[string(text)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errNoMatchingCase
|
return &noMatchingCaseError{}
|
||||||
}
|
}
|
||||||
*v = c
|
*v = c
|
||||||
return nil
|
return nil
|
||||||
@@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
|
|||||||
|
|
||||||
const linearScanThreshold = 16
|
const linearScanThreshold = 16
|
||||||
|
|
||||||
var (
|
type emptyTextError struct{}
|
||||||
errEmpty = &stringError{"empty text"}
|
|
||||||
errNoMatchingCase = &stringError{"no matching case"}
|
|
||||||
)
|
|
||||||
|
|
||||||
type stringError struct {
|
func (*emptyTextError) Error() string { return "empty text" }
|
||||||
err string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err *stringError) Error() string {
|
type noMatchingCaseError struct{}
|
||||||
return err.err
|
|
||||||
}
|
func (*noMatchingCaseError) Error() string { return "no matching case" }
|
||||||
|
|||||||
Reference in New Issue
Block a user