Skip to content

Commit ddec18c

Browse files
committed
[dev.typeparams] cmd/compile/internal/types2: overlapping embedded interfaces requires go1.14
Add respective check to type checker. Enables another excluded test in test/run.go. This CL completes the currently required checks for language compatibility in types2. Updates #31793. Change-Id: Icececff9e6023d38f600c93bcb54cdcafcf501b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/290911 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent fdf3496 commit ddec18c

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/cmd/compile/internal/types2/stdlib_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ func TestStdFixed(t *testing.T) {
192192
"issue22200b.go", // go/types does not have constraints on stack size
193193
"issue25507.go", // go/types does not have constraints on stack size
194194
"issue20780.go", // go/types does not have constraints on stack size
195-
"issue34329.go", // go/types does not have constraints on language level (-lang=go1.13) (see #31793)
196195
"issue42058a.go", // go/types does not have constraints on channel element size
197196
"issue42058b.go", // go/types does not have constraints on channel element size
198197
"bug251.go", // issue #34333 which was exposed with fix for #34151
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Check Go language version-specific errors.
6+
7+
package go1_13 // go1.13
8+
9+
// interface embedding
10+
11+
type I interface { m() }
12+
13+
type _ interface {
14+
m()
15+
I // ERROR "duplicate method m"
16+
}
17+
18+
type _ interface {
19+
I
20+
I // ERROR "duplicate method m"
21+
}

src/cmd/compile/internal/types2/typexpr.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,13 @@ func (check *Checker) completeInterface(pos syntax.Pos, ityp *Interface) {
943943
check.errorf(pos, "duplicate method %s", m.name)
944944
check.errorf(mpos[other.(*Func)], "\tother declaration of %s", m.name) // secondary error, \t indented
945945
default:
946-
// check method signatures after all types are computed (issue #33656)
946+
// We have a duplicate method name in an embedded (not explicitly declared) method.
947+
// Check method signatures after all types are computed (issue #33656).
948+
// If we're pre-go1.14 (overlapping embeddings are not permitted), report that
949+
// error here as well (even though we could do it eagerly) because it's the same
950+
// error message.
947951
check.atEnd(func() {
948-
if !check.identical(m.typ, other.Type()) {
952+
if !check.allowVersion(m.pkg, 1, 14) || !check.identical(m.typ, other.Type()) {
949953
check.errorf(pos, "duplicate method %s", m.name)
950954
check.errorf(mpos[other.(*Func)], "\tother declaration of %s", m.name) // secondary error, \t indented
951955
}

test/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,6 @@ var excluded = map[string]bool{
19641964
"fixedbugs/issue28079b.go": true, // types2 reports follow-on errors
19651965
"fixedbugs/issue28268.go": true, // types2 reports follow-on errors
19661966
"fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error
1967-
"fixedbugs/issue34329.go": true, // types2 is missing support for -lang flag
19681967
"fixedbugs/issue41575.go": true, // types2 reports alternative positions in separate error
19691968
"fixedbugs/issue42058a.go": true, // types2 doesn't report "channel element type too large"
19701969
"fixedbugs/issue42058b.go": true, // types2 doesn't report "channel element type too large"

0 commit comments

Comments
 (0)