Skip to content

Commit 9480f47

Browse files
committed
compiler: use an interface to check if GoVersion() exists
This permits TinyGo to compile with Go 1.21.
1 parent b99d6a2 commit 9480f47

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
@@ -465,9 +465,12 @@ func (c *compilerContext) isValidWasmType(typ types.Type, site wasmSite) bool {
465465
if typ.NumFields() == 0 {
466466
return true
467467
}
468-
var hasHostLayout bool
469-
if !goenv.WantGoVersion(c.pkg.GoVersion(), 1, 23) {
470-
hasHostLayout = true // package structs does not exist before go1.23
468+
hasHostLayout := true // default to true before detecting Go version
469+
// (*types.Package).GoVersion added in go1.21
470+
if gv, ok := any(c.pkg).(interface{ GoVersion() string }); ok {
471+
if goenv.WantGoVersion(gv.GoVersion(), 1, 23) {
472+
hasHostLayout = false // package structs added in go1.23
473+
}
471474
}
472475
for i := 0; i < typ.NumFields(); i++ {
473476
ftyp := typ.Field(i).Type()

0 commit comments

Comments
 (0)