aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/typexpr.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-01-15 18:19:00 -0800
committerRobert Griesemer <gri@golang.org>2021-01-20 05:50:46 +0000
commitd8796b5670d46a4197fc5e81a32d127c45ab6557 (patch)
treeec7789dbc126130c2f0b3d30b1b12695acd6d18f /src/cmd/compile/internal/types2/typexpr.go
parent48a3cb399da872554f6ea13e1e92b3c8c73fec95 (diff)
downloadgo-d8796b5670d46a4197fc5e81a32d127c45ab6557.tar.gz
go-d8796b5670d46a4197fc5e81a32d127c45ab6557.zip
[dev.typeparams] cmd/compile/internal/types2: report type of nil based on context
With this CL, the type reported for uses of the predeclared identifier nil changes from untyped nil to the type of the context within which nil is used, matching the behaviour of types2 for other untyped types. If an untyped nil value is assigned or converted to an interface, the nil expression is given the interface type. The predicate TypeAndValue.IsNil doesn't change in behavior, it still reports whether the relevant expression is a (typed or untyped) nil value. Change-Id: Id766468f3f3f2a53e4c55e1e6cd521e459c4a94f Reviewed-on: https://go-review.googlesource.com/c/go/+/284218 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/typexpr.go')
-rw-r--r--src/cmd/compile/internal/types2/typexpr.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go
index d30f2fef26..f0461d5895 100644
--- a/src/cmd/compile/internal/types2/typexpr.go
+++ b/src/cmd/compile/internal/types2/typexpr.go
@@ -111,7 +111,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *Named, wantType boo
x.mode = builtin
case *Nil:
- x.mode = value
+ x.mode = nilvalue
default:
unreachable()
@@ -631,11 +631,8 @@ func (check *Checker) typOrNil(e syntax.Expr) Type {
case typexpr:
check.instantiatedOperand(&x)
return x.typ
- case value:
- if x.isNil() {
- return nil
- }
- fallthrough
+ case nilvalue:
+ return nil
default:
check.errorf(&x, "%s is not a type", &x)
}