Skip to content

Commit 4f8672c

Browse files
ydnardeadprogram
authored andcommitted
internal/cm: change error type from struct{string}
This is a temporary fix until [email protected] is released, and package internal/cm and internal/wasi can be regenerated. See #4810 for more information.
1 parent a7416e7 commit 4f8672c

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/internal/cm/case.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
99
if len(cases) <= linearScanThreshold {
1010
return func(v *T, text []byte) error {
1111
if len(text) == 0 {
12-
return errEmpty
12+
return &emptyTextError{}
1313
}
1414
s := string(text)
1515
for i := 0; i < len(cases); i++ {
@@ -18,7 +18,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
1818
return nil
1919
}
2020
}
21-
return errNoMatchingCase
21+
return &noMatchingCaseError{}
2222
}
2323
}
2424

@@ -29,11 +29,11 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
2929

3030
return func(v *T, text []byte) error {
3131
if len(text) == 0 {
32-
return errEmpty
32+
return &emptyTextError{}
3333
}
3434
c, ok := m[string(text)]
3535
if !ok {
36-
return errNoMatchingCase
36+
return &noMatchingCaseError{}
3737
}
3838
*v = c
3939
return nil
@@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
4242

4343
const linearScanThreshold = 16
4444

45-
var (
46-
errEmpty = &stringError{"empty text"}
47-
errNoMatchingCase = &stringError{"no matching case"}
48-
)
45+
type emptyTextError struct{}
4946

50-
type stringError struct {
51-
err string
52-
}
47+
func (*emptyTextError) Error() string { return "empty text" }
5348

54-
func (err *stringError) Error() string {
55-
return err.err
56-
}
49+
type noMatchingCaseError struct{}
50+
51+
func (*noMatchingCaseError) Error() string { return "no matching case" }

0 commit comments

Comments
 (0)