File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 6
6
"go.bytecodealliance.org/wit"
7
7
)
8
8
9
- // variantShape returns the type with the greatest size.
9
+ // variantShape returns the type with the greatest size that is not a bool .
10
10
// If there are multiple types with the same size, it returns
11
11
// the first type that contains a pointer.
12
12
func variantShape (types []wit.Type ) wit.Type {
@@ -19,6 +19,12 @@ func variantShape(types []wit.Type) wit.Type {
19
19
return - 1
20
20
case a .Size () < b .Size ():
21
21
return 1
22
+ case ! isBool (a ) && isBool (b ):
23
+ // bool cannot be used as variant shape
24
+ // See https://github.com/bytecodealliance/go-modules/issues/284
25
+ return - 1
26
+ case isBool (a ) && ! isBool (b ):
27
+ return 1
22
28
case wit .HasPointer (a ) && ! wit .HasPointer (b ):
23
29
return - 1
24
30
case ! wit .HasPointer (a ) && wit .HasPointer (b ):
@@ -30,6 +36,16 @@ func variantShape(types []wit.Type) wit.Type {
30
36
return types [0 ]
31
37
}
32
38
39
+ func isBool (t wit.TypeDefKind ) bool {
40
+ switch t := t .(type ) {
41
+ case wit.Bool :
42
+ return true
43
+ case * wit.TypeDef :
44
+ return isBool (t .Root ().Kind )
45
+ }
46
+ return false
47
+ }
48
+
33
49
// variantAlign returns the type with the largest alignment.
34
50
func variantAlign (types []wit.Type ) wit.Type {
35
51
if len (types ) == 0 {
You can’t perform that action at this time.
0 commit comments