From 5c7a005266f84ecea26859619630a862eccc0d48 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 3 Jun 2016 13:21:55 -0700 Subject: [PATCH] spec: ignore struct tags when converting structs This is a backwards-compatible language change. Per the proposal (#16085), the rules for conversions are relaxed such that struct tags in any of the structs involved in the conversion are ignored (recursively). Because this is loosening the existing rules, code that compiled so far will continue to compile. For #16085. Fixes #6858. Change-Id: I0feef651582db5f23046a2331fc3f179ae577c45 Reviewed-on: https://go-review.googlesource.com/24190 Reviewed-by: Russ Cox --- doc/go_spec.html | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 1d0ea22c7c..6e07c945e1 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -3837,10 +3837,12 @@ in any of these cases: to T.
  • - x's type and T have identical + ignoring struct tags (see below), + x's type and T have identical underlying types.
  • + ignoring struct tags (see below), x's type and T are unnamed pointer types and their pointer base types have identical underlying types.
  • @@ -3860,6 +3862,31 @@ in any of these cases: +

    +Struct tags are ignored when comparing struct types +for identity for the purpose of conversion: +

    + +
    +type Person struct {
    +	Name    string
    +	Address *struct {
    +		Street string
    +		City   string
    +	}
    +}
    +
    +var data *struct {
    +	Name    string `json:"name"`
    +	Address *struct {
    +		Street string `json:"street"`
    +		City   string `json:"city"`
    +	} `json:"address"`
    +}
    +
    +var person = (*Person)(data)  // ignoring tags, the underlying types are identical
    +
    +

    Specific rules apply to (non-constant) conversions between numeric types or to and from a string type. -- 2.48.1