Skip to content

Commit 39a8c8c

Browse files
cuonglmcherrymui
authored andcommitted
[release-branch.go1.18] cmd/compile: fix wrong dict param when getting dict type
CL 338129 added getDictionaryType to get the dictionary type from the specified dict param, but still using the one in info.dictParam, which is wrong. Fixes #51669 Change-Id: Ie13460c1e5751c4c5fc44479a44f6eed8b3b06e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/391994 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Trust: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/392614
1 parent 9d73848 commit 39a8c8c

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/cmd/compile/internal/noder/stencil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ func getDictionaryType(info *instInfo, dictParam *ir.Name, pos src.XPos, i int)
898898
base.Fatalf(fmt.Sprintf("bad dict index %d", i))
899899
}
900900

901-
r := getDictionaryEntry(pos, info.dictParam, i, info.dictInfo.startSubDict)
901+
r := getDictionaryEntry(pos, dictParam, i, info.dictInfo.startSubDict)
902902
// change type of retrieved dictionary entry to *byte, which is the
903903
// standard typing of a *runtime._type in the compiler
904904
typed(types.Types[types.TUINT8].PtrTo(), r)

test/typeparam/mdempsky/13b.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// run -gcflags="-G=3 -l"
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
// Interface which will be used as a regular interface type and as a type bound.
10+
type Mer interface{
11+
M()
12+
}
13+
14+
// Interface that is a superset of Mer.
15+
type Mer2 interface {
16+
M()
17+
String() string
18+
}
19+
20+
func F[T Mer](t T) {
21+
T.M(t)
22+
t.M()
23+
}
24+
25+
type MyMer int
26+
27+
func (MyMer) M() {}
28+
func (MyMer) String() string {
29+
return "aa"
30+
}
31+
32+
// Parameterized interface
33+
type Abs[T any] interface {
34+
Abs() T
35+
}
36+
37+
func G[T Abs[U], U any](t T) {
38+
T.Abs(t)
39+
t.Abs()
40+
}
41+
42+
type MyInt int
43+
func (m MyInt) Abs() MyInt {
44+
if m < 0 {
45+
return -m
46+
}
47+
return m
48+
}
49+
50+
type Abs2 interface {
51+
Abs() MyInt
52+
}
53+
54+
55+
func main() {
56+
mm := MyMer(3)
57+
ms := struct{ Mer }{Mer: mm }
58+
59+
// Testing F with an interface type arg: Mer and Mer2
60+
F[Mer](mm)
61+
F[Mer2](mm)
62+
F[struct{ Mer }](ms)
63+
F[*struct{ Mer }](&ms)
64+
65+
ms2 := struct { MyMer }{MyMer: mm}
66+
ms3 := struct { *MyMer }{MyMer: &mm}
67+
68+
// Testing F with a concrete type arg
69+
F[MyMer](mm)
70+
F[*MyMer](&mm)
71+
F[struct{ MyMer }](ms2)
72+
F[struct{ *MyMer }](ms3)
73+
F[*struct{ MyMer }](&ms2)
74+
F[*struct{ *MyMer }](&ms3)
75+
76+
// Testing G with a concrete type args
77+
mi := MyInt(-3)
78+
G[MyInt,MyInt](mi)
79+
80+
// Interface Abs[MyInt] holding an mi.
81+
intMi := Abs[MyInt](mi)
82+
// First type arg here is Abs[MyInt], an interface type.
83+
G[Abs[MyInt],MyInt](intMi)
84+
}

0 commit comments

Comments
 (0)