aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iimport.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-06-02 00:03:25 -0700
committerDan Scales <danscales@google.com>2021-06-02 23:10:42 +0000
commit97cb0113a358a24931bc91c956da0cb023f2776c (patch)
tree0baa45bac527ebaecc3b0eee3e1de3ac53b4cca1 /src/cmd/compile/internal/typecheck/iimport.go
parent6b1cdeaef3099b32d244cef7bb5adc4d7b7628fc (diff)
downloadgo-97cb0113a358a24931bc91c956da0cb023f2776c.tar.gz
go-97cb0113a358a24931bc91c956da0cb023f2776c.zip
[dev.typeparams] cmd/compile: fix export/import of constants with typeparam type
A constant will have a TYPEPARAM type if it appears in a place where it must match that typeparam type (e.g. in a binary operation with a variable of that typeparam type). If so, then we must write out its actual constant kind as well, so its constant val can be read in properly during import. Fixed some export/import tests which were casting some untyped constants to avoid this problem. Change-Id: I285ad8f1c8febbe526769c96e6b27acbd23050f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/324189 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iimport.go')
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 4c31e47378..96107b657b 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -400,19 +400,39 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
}
func (p *importReader) value(typ *types.Type) constant.Value {
- switch constTypeOf(typ) {
+ var kind constant.Kind
+ var valType *types.Type
+
+ if typ.Kind() == types.TTYPEPARAM {
+ // If a constant had a typeparam type, then we wrote out its
+ // actual constant kind as well.
+ kind = constant.Kind(p.int64())
+ switch kind {
+ case constant.Int:
+ valType = types.Types[types.TINT64]
+ case constant.Float:
+ valType = types.Types[types.TFLOAT64]
+ case constant.Complex:
+ valType = types.Types[types.TCOMPLEX128]
+ }
+ } else {
+ kind = constTypeOf(typ)
+ valType = typ
+ }
+
+ switch kind {
case constant.Bool:
return constant.MakeBool(p.bool())
case constant.String:
return constant.MakeString(p.string())
case constant.Int:
var i big.Int
- p.mpint(&i, typ)
+ p.mpint(&i, valType)
return constant.Make(&i)
case constant.Float:
- return p.float(typ)
+ return p.float(valType)
case constant.Complex:
- return makeComplex(p.float(typ), p.float(typ))
+ return makeComplex(p.float(valType), p.float(valType))
}
base.Fatalf("unexpected value type: %v", typ)