Skip to content

Commit 7736106

Browse files
authored
Merge pull request #1133 from nevkontakte/go1.18
Final cleanups for Go 1.18
2 parents 6ca1089 + 918cc1e commit 7736106

File tree

12 files changed

+119
-47
lines changed

12 files changed

+119
-47
lines changed

.github/workflows/measure-size.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fetch-depth: 0
1212
- uses: actions/setup-go@v2
1313
with:
14-
go-version: '~1.18.1'
14+
go-version: '~1.18.4'
1515
- uses: gopherjs/output-size-action/measure@main
1616
with:
1717
name: jQuery TodoMVC

build/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke
279279
s := spec.(*ast.TypeSpec)
280280
if replacedDeclNames[s.Name.Name] {
281281
s.Name = ast.NewIdent("_")
282+
s.Type = &ast.StructType{Struct: s.Pos(), Fields: &ast.FieldList{}}
283+
s.TypeParams = nil
282284
}
283285
}
284286
case token.VAR, token.CONST:

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ workflows:
5454
parameters:
5555
go_version:
5656
type: string
57-
default: "1.18.1"
57+
default: "1.18.4"
5858
nvm_version:
5959
type: string
6060
default: "0.38.0"

compiler/natives/fs_vfsdata.go

Lines changed: 46 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build js
2+
3+
package doc
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
)
9+
10+
func compareSlices(t *testing.T, name string, got, want interface{}, compareElem interface{}) {
11+
// TODO(nevkontakte): Remove this override after generics are supported.
12+
// https://github.com/gopherjs/gopherjs/issues/1013.
13+
switch got.(type) {
14+
case []*Func:
15+
got := got.([]*Func)
16+
want := want.([]*Func)
17+
compareElem := compareElem.(func(t *testing.T, msg string, got, want *Func))
18+
if len(got) != len(want) {
19+
t.Errorf("%s: got %d, want %d", name, len(got), len(want))
20+
}
21+
for i := 0; i < len(got) && i < len(want); i++ {
22+
compareElem(t, fmt.Sprintf("%s[%d]", name, i), got[i], want[i])
23+
}
24+
case []*Type:
25+
got := got.([]*Type)
26+
want := want.([]*Type)
27+
compareElem := compareElem.(func(t *testing.T, msg string, got, want *Type))
28+
if len(got) != len(want) {
29+
t.Errorf("%s: got %d, want %d", name, len(got), len(want))
30+
}
31+
for i := 0; i < len(got) && i < len(want); i++ {
32+
compareElem(t, fmt.Sprintf("%s[%d]", name, i), got[i], want[i])
33+
}
34+
default:
35+
t.Errorf("unexpected argument type %T", got)
36+
}
37+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build js
2+
3+
package parser
4+
5+
import (
6+
"testing"
7+
)
8+
9+
func TestParseDepthLimit(t *testing.T) {
10+
t.Skip("causes call stack exhaustion on js/ecmascript")
11+
}

compiler/natives/src/reflect/reflect.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,28 +1295,6 @@ func getJsTag(tag string) string {
12951295
return ""
12961296
}
12971297

1298-
// CanConvert reports whether the value v can be converted to type t. If
1299-
// v.CanConvert(t) returns true then v.Convert(t) will not panic.
1300-
//
1301-
// TODO(nevkontakte): this overlay can be removed after
1302-
// https://github.com/golang/go/pull/48346 is in the lastest stable Go release.
1303-
func (v Value) CanConvert(t Type) bool {
1304-
vt := v.Type()
1305-
if !vt.ConvertibleTo(t) {
1306-
return false
1307-
}
1308-
// Currently the only conversion that is OK in terms of type
1309-
// but that can panic depending on the value is converting
1310-
// from slice to pointer-to-array.
1311-
if vt.Kind() == Slice && t.Kind() == Ptr && t.Elem().Kind() == Array {
1312-
n := t.Elem().Len()
1313-
if n > v.Len() { // Avoiding use of unsafeheader.Slice here.
1314-
return false
1315-
}
1316-
}
1317-
return true
1318-
}
1319-
13201298
func (v Value) Index(i int) Value {
13211299
switch k := v.kind(); k {
13221300
case Array:

compiler/natives/src/reflect/reflect_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ func TestMethodCallValueCodePtr(t *testing.T) {
285285
t.Skip("methodValueCallCodePtr() is not applicable in GopherJS")
286286
}
287287

288+
type B struct{}
289+
290+
//gopherjs:prune-original
288291
func TestIssue50208(t *testing.T) {
289292
t.Skip("This test required generics, which are not yet supported: https://github.com/gopherjs/gopherjs/issues/1013")
290293
}

compiler/natives/src/syscall/js/js.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ func init() {
148148

149149
func ValueOf(x interface{}) Value {
150150
switch x := x.(type) {
151-
case Wrapper:
152-
return x.JSValue()
153151
case Value:
154152
return x
155153
case Func:
@@ -361,10 +359,6 @@ func (e *ValueError) Error() string {
361359
return "syscall/js: call of " + e.Method + " on " + e.Type.String()
362360
}
363361

364-
type Wrapper interface {
365-
JSValue() Value
366-
}
367-
368362
// CopyBytesToGo copies bytes from the Uint8Array src to dst.
369363
// It returns the number of bytes copied, which will be the minimum of the lengths of src and dst.
370364
// CopyBytesToGo panics if src is not an Uint8Array.

compiler/package.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"go/ast"
88
"go/constant"
9+
"go/scanner"
910
"go/token"
1011
"go/types"
1112
"sort"
@@ -398,6 +399,13 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
398399
var mainFunc *types.Func
399400
for _, fun := range functions {
400401
o := funcCtx.pkgCtx.Defs[fun.Name].(*types.Func)
402+
403+
if fun.Type.TypeParams.NumFields() > 0 {
404+
return nil, scanner.Error{
405+
Pos: fileSet.Position(fun.Type.TypeParams.Pos()),
406+
Msg: fmt.Sprintf("function %s: type parameters are not supported by GopherJS: https://github.com/gopherjs/gopherjs/issues/1013", o.Name()),
407+
}
408+
}
401409
funcInfo := funcCtx.pkgCtx.FuncDeclInfos[o]
402410
d := Decl{
403411
FullName: o.FullName(),
@@ -480,6 +488,14 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
480488
continue
481489
}
482490
typeName := funcCtx.objectName(o)
491+
492+
if named, ok := o.Type().(*types.Named); ok && named.TypeParams().Len() > 0 {
493+
return nil, scanner.Error{
494+
Pos: fileSet.Position(o.Pos()),
495+
Msg: fmt.Sprintf("type %s: type parameters are not supported by GopherJS: https://github.com/gopherjs/gopherjs/issues/1013", o.Name()),
496+
}
497+
}
498+
483499
d := Decl{
484500
Vars: []string{typeName},
485501
DceObjectFilter: o.Name(),

compiler/version_check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// Version is the GopherJS compiler version string.
16-
const Version = "1.18.0+go1.18.1"
16+
const Version = "1.18.0+go1.18.4"
1717

1818
// GoVersion is the current Go 1.x version that GopherJS is compatible with.
1919
const GoVersion = 18

tests/gorepo/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ var knownFails = map[string]failReason{
156156
"fixedbugs/issue49665.go": {category: other, desc: "attempts to pass -gcflags=-G=3 to enable generics, GopherJS doesn't expect the flag; re-enable in Go 1.19 where the flag is removed"},
157157
"fixedbugs/issue48898.go": {category: other, desc: "https://github.com/gopherjs/gopherjs/issues/1128"},
158158
"fixedbugs/issue48536.go": {category: usesUnsupportedPackage, desc: "https://github.com/gopherjs/gopherjs/issues/1130"},
159+
"fixedbugs/issue53600.go": {category: lowLevelRuntimeDifference, desc: "GopherJS println format is different from Go's"},
159160
}
160161

161162
type failCategory uint8

0 commit comments

Comments
 (0)