Skip to content

Commit

Permalink
stdlib: support of go1.18 and go1.19, remove go1.16 and go1.17
Browse files Browse the repository at this point in the history
In addition:
- extract commmand now skips exported generics in runtime wrappers
- interp_consistent_test.go fixed for go1.18 and go1.19
- move minimal version of go compiler to go1.18

Note that this version is incompatible with go1.17 and before due
to the major changes in the stdlib go parser.

To be merged once go1.19 is officially released (not before).
  • Loading branch information
mvertes authored Jul 20, 2022
1 parent d9c402e commit dc082b5
Show file tree
Hide file tree
Showing 959 changed files with 198,255 additions and 193,854 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
go-version: [ 1.16, 1.17 ]
go-version: [ 1.18, 1.19.0-rc2 ]
os: [ubuntu-latest, macos-latest, windows-latest]

include:
Expand All @@ -34,6 +34,7 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
stable: false

# https://github.com/marketplace/actions/checkout
- name: Checkout code
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
pull_request:

env:
GO_VERSION: 1.17
GOLANGCI_LINT_VERSION: v1.42.1
GO_VERSION: 1.18
GOLANGCI_LINT_VERSION: v1.47.1

jobs:

Expand Down Expand Up @@ -45,12 +45,13 @@ jobs:
needs: linting
strategy:
matrix:
go-version: [ 1.16, 1.17 ]
go-version: [ 1.18, 1.19.0-rc2 ]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
stable: false

- name: Check out code
uses: actions/checkout@v2
Expand All @@ -75,13 +76,14 @@ jobs:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi
strategy:
matrix:
go-version: [ 1.16, 1.17 ]
go-version: [ 1.18, 1.19.0-rc2 ]

steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
stable: false

- name: Check out code
uses: actions/checkout@v2
Expand Down
11 changes: 10 additions & 1 deletion .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"scopelint", # deprecated
"interfacer", # deprecated
"maligned", # deprecated
"exhaustivestruct", # deprecated
"lll",
"gas",
"dupl",
Expand All @@ -49,10 +50,15 @@
"wrapcheck",
"nestif",
"exhaustive",
"exhaustivestruct",
"exhaustruct",
"forbidigo",
"ifshort",
"forcetypeassert",
"varnamelen",
"nosnakecase",
"nonamedreturns",
"nilnil",
"maintidx",
"errorlint", # TODO: must be reactivate before fixes
]

Expand Down Expand Up @@ -81,3 +87,6 @@
[[issues.exclude-rules]]
path = "interp/interp_eval_test.go"
linters = ["thelper"]
[[issues.exclude-rules]]
path = "interp/debugger.go"
linters = ["containedctx"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It powers executable Go scripts and plugins, in embedded interpreters or interac
* Works everywhere Go works
* All Go & runtime resources accessible from script (with control)
* Security: `unsafe` and `syscall` packages neither used nor exported by default
* Support Go 1.16 and Go 1.17 (the latest 2 major releases)
* Support Go 1.18 and Go 1.19 (the latest 2 major releases)

## Install

Expand Down
4 changes: 1 addition & 3 deletions example/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package fs1

import (
"testing"

// only available from 1.16.
"testing/fstest"
"testing/fstest" // only available from 1.16.

"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
Expand Down
7 changes: 6 additions & 1 deletion extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, err
case *types.Var:
val[name] = Val{pname, true}
case *types.TypeName:
// Skip type if it is generic.
if t, ok := o.Type().(*types.Named); ok && t.TypeParams().Len() > 0 {
continue
}

typ[name] = pname
if t, ok := o.Type().Underlying().(*types.Interface); ok {
var methods []Method
Expand Down Expand Up @@ -463,7 +468,7 @@ func GetMinor(part string) string {
return minor
}

const defaultMinorVersion = 17
const defaultMinorVersion = 19

func genBuildTags() (string, error) {
version := runtime.Version()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/traefik/yaegi

go 1.16
go 1.18
1 change: 1 addition & 0 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ const (
func initUniverse() *scope {
sc := &scope{global: true, sym: map[string]*symbol{
// predefined Go types
"any": {kind: typeSym, typ: &itype{cat: interfaceT, str: "any"}},
"bool": {kind: typeSym, typ: &itype{cat: boolT, name: "bool", str: "bool"}},
"byte": {kind: typeSym, typ: &itype{cat: uint8T, name: "uint8", str: "uint8"}},
"complex64": {kind: typeSym, typ: &itype{cat: complex64T, name: "complex64", str: "complex64"}},
Expand Down
34 changes: 14 additions & 20 deletions interp/interp_consistent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -181,12 +180,6 @@ func TestInterpConsistencyBuild(t *testing.T) {
}

func TestInterpErrorConsistency(t *testing.T) {
if runtime.Version() >= "go1.18" {
// Error messages have changed a lot between go1.17 and go1.18.
// Skip testing on go1.18 and beyond while we support go1.17.
// It can be re-enabled after dropping go1.17.
t.Skip("skip go1.18+")
}
testCases := []struct {
fileName string
expectedInterp string
Expand All @@ -195,12 +188,12 @@ func TestInterpErrorConsistency(t *testing.T) {
{
fileName: "assign11.go",
expectedInterp: "6:2: assignment mismatch: 3 variables but fmt.Println returns 2 values",
expectedExec: "6:10: assignment mismatch: 3 variables but fmt.Println returns 2 values",
expectedExec: "6:12: assignment mismatch: 3 variables but fmt.Println returns 2 values",
},
{
fileName: "assign12.go",
expectedInterp: "6:2: assignment mismatch: 3 variables but fmt.Println returns 2 values",
expectedExec: "6:10: assignment mismatch: 3 variables but fmt.Println returns 2 values",
expectedExec: "6:13: assignment mismatch: 3 variables but fmt.Println returns 2 values",
},
{
fileName: "bad0.go",
Expand All @@ -220,46 +213,47 @@ func TestInterpErrorConsistency(t *testing.T) {
{
fileName: "const9.go",
expectedInterp: "5:2: constant definition loop",
expectedExec: "5:2: constant definition loop",
expectedExec: "5:2: initialization loop for b",
},
{
fileName: "if2.go",
expectedInterp: "7:5: non-bool used as if condition",
expectedExec: "7:2: non-bool i % 1000000 (type int) used as if condition",
expectedExec: "7:5: non-boolean condition in if statement",
},
{
fileName: "for7.go",
expectedInterp: "4:14: non-bool used as for condition",
expectedExec: "4:2: non-bool i (type int) used as for condition",
expectedExec: "4:14: non-boolean condition in for statement",
},
{
fileName: "fun21.go",
expectedInterp: "4:2: not enough arguments to return",
expectedExec: "4:2: not enough arguments to return",
expectedExec: "4:2: not enough return values",
},
{
fileName: "fun22.go",
expectedInterp: "6:2: not enough arguments in call to time.Date",
expectedExec: "6:11: not enough arguments in call to time.Date",
expectedExec: "6:2: not enough arguments in call to time.Date",
},
{
fileName: "fun23.go",
expectedInterp: "3:17: too many arguments to return",
expectedExec: "3:17: too many arguments to return",
expectedExec: "3:24: too many return values",
},
{
fileName: "issue-1093.go",
expectedInterp: "9:6: cannot use type untyped string as type int in assignment",
expectedExec: `9:4: cannot use "a" + b() (type string) as type int in assignment`,
expectedExec: `9:6: cannot use "a" + b() (value of type string) as type int in assignment`,
},
{
fileName: "op1.go",
expectedInterp: "5:2: invalid operation: mismatched types int and untyped float",
expectedExec: "5:4: constant 1.3 truncated to integer",
expectedExec: "5:7: 1.3 (untyped float constant) truncated to int",
},
{
fileName: "bltn0.go",
expectedInterp: "4:7: use of builtin println not in function call",
expectedExec: "4:7: println (built-in) must be called",
},
{
fileName: "import6.go",
Expand All @@ -274,17 +268,17 @@ func TestInterpErrorConsistency(t *testing.T) {
{
fileName: "switch9.go",
expectedInterp: "9:3: cannot fallthrough in type switch",
expectedExec: "9:3: cannot fallthrough in type switch",
expectedExec: "fallthrough",
},
{
fileName: "switch13.go",
expectedInterp: "9:2: i is not a type",
expectedExec: "9:2: i (type interface {}) is not a type",
expectedExec: "9:7: i (variable of type interface{}) is not a type",
},
{
fileName: "switch19.go",
expectedInterp: "37:2: duplicate case Bir in type switch",
expectedExec: "37:2: duplicate case Bir in type switch",
expectedExec: "37:7: duplicate case Bir in type switch",
},
}

Expand Down
10 changes: 5 additions & 5 deletions interp/interp_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ const goMinorVersionTest = 16

func TestHasIOFS(t *testing.T) {
code := `
// +build go1.16
// +build go1.18
package main
Expand Down Expand Up @@ -1048,6 +1048,8 @@ func main() {
var minor int
var err error
version := runtime.Version()
version = strings.Replace(version, "beta", ".", 1)
version = strings.Replace(version, "rc", ".", 1)
fields := strings.Fields(version)
// Go stable
if len(fields) == 1 {
Expand Down Expand Up @@ -1597,10 +1599,8 @@ func TestREPLCommands(t *testing.T) {
if testing.Short() {
return
}
_ = os.Setenv("YAEGI_PROMPT", "1") // To force prompts over non-tty streams
defer func() {
_ = os.Setenv("YAEGI_PROMPT", "0")
}()
t.Setenv("YAEGI_PROMPT", "1") // To force prompts over non-tty streams

allDone := make(chan bool)
runREPL := func() {
done := make(chan error)
Expand Down
5 changes: 1 addition & 4 deletions interp/interp_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func TestFile(t *testing.T) {
filePath := "../_test/str.go"
runCheck(t, filePath)

defer func() {
_ = os.Setenv("YAEGI_SPECIAL_STDIO", "0")
}()
_ = os.Setenv("YAEGI_SPECIAL_STDIO", "1")
t.Setenv("YAEGI_SPECIAL_STDIO", "1")

baseDir := filepath.Join("..", "_test")
files, err := os.ReadDir(baseDir)
Expand Down
49 changes: 0 additions & 49 deletions stdlib/go1_16_archive_tar.go

This file was deleted.

36 changes: 0 additions & 36 deletions stdlib/go1_16_archive_zip.go

This file was deleted.

Loading

0 comments on commit dc082b5

Please sign in to comment.