Skip to content

cmd/compile: inconsistent behaviors in judging whether or not two types are identical #24721

Closed
@dotaheor

Description

@dotaheor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

package m3

import "time"

type t = time.Time
type T = time.Time

type A = struct{t}
type B = struct{T}
import "m3"
import "time"

type t = time.Time
type T = time.Time

type A = struct{t}
type B = struct{T}

func main() {
   var a, b interface{} = m3.A{}, m3.B{}
   var x, y interface{} = A{}, B{}
   println(a == x) // true
   println(b == y) // true
   
   _ = A(m3.A{}) // cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }
   _ = B(m3.B{}) // ok
   
   println(a == b) // true
   println(x == y) // true
   _ = B(A{})       // cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }
   _ = m3.A(m3.B{}) // cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }
}

What did you expect to see?

No errors, [edit: or all println calls, except the second, print false].

What did you see instead?

./main.go:18:9: cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }
./main.go:23:9: cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }
./main.go:24:12: cannot convert struct { time.Time } literal (type struct { time.Time }) to type struct { time.Time }

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.early-in-cycleA change that should be done early in the 3 month dev cycle.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions