Skip to content

Commit 08bda1a

Browse files
committed
compiler: use an interface to check if GoVersion() exists
This permits TinyGo to compile with Go 1.21.
1 parent 6a7a28d commit 08bda1a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/symbol.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,12 @@ func (c *compilerContext) isValidWasmType(typ types.Type, site wasmSite) bool {
471471
if typ.NumFields() == 0 {
472472
return true
473473
}
474-
var hasHostLayout bool
475-
if !goenv.WantGoVersion(c.pkg.GoVersion(), 1, 23) {
476-
hasHostLayout = true // package structs does not exist before go1.23
474+
hasHostLayout := true // default to true before detecting Go version
475+
// (*types.Package).GoVersion added in go1.21
476+
if gv, ok := any(c.pkg).(interface{ GoVersion() string }); ok {
477+
if goenv.WantGoVersion(gv.GoVersion(), 1, 23) {
478+
hasHostLayout = false // package structs added in go1.23
479+
}
477480
}
478481
for i := 0; i < typ.NumFields(); i++ {
479482
ftyp := typ.Field(i).Type()

0 commit comments

Comments
 (0)