aboutsummaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-01-18 20:05:14 +0100
committerAyke van Laethem <[email protected]>2024-01-19 13:46:27 +0100
commit08ca1d13d09b62765e6945ae7f1e33df3a156997 (patch)
treeadd7cc62cc554fdb5294ba20932408b7caf983e4 /loader
parent53db436a7d3bdfe7682c97e21fe1249a29156a35 (diff)
downloadtinygo-08ca1d13d09b62765e6945ae7f1e33df3a156997.tar.gz
tinygo-08ca1d13d09b62765e6945ae7f1e33df3a156997.zip
loader: enforce Go language version in the type checker
This means for example that ranging over integers will only work when setting the Go version to go1.22 or later in the go.mod file.
Diffstat (limited to 'loader')
-rw-r--r--loader/loader.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/loader/loader.go b/loader/loader.go
index 9b46aa614..60d0f7eba 100644
--- a/loader/loader.go
+++ b/loader/loader.go
@@ -378,6 +378,12 @@ func (p *Package) Check() error {
typeErrors = append(typeErrors, err)
}
checker.Importer = p
+ if p.Module.GoVersion != "" {
+ // Setting the Go version for a module makes sure the type checker
+ // errors out on language features not supported in that particular
+ // version.
+ checker.GoVersion = "go" + p.Module.GoVersion
+ }
// Do typechecking of the package.
packageName := p.ImportPath