Skip to content

reflect: inconsistent results between reflection and non-reflection #29469

@zigo101

Description

@zigo101

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

go version go1.11.3 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

package main

import "reflect"

var _ = reflect.ValueOf

func main() {
	type C chan int
	type C1 chan<- int
	type C2 <-chan int
	var c C
	_ = chan<- int(c)   // ok
	_ = (<-chan int)(c) // ok
	//_ = C1(c)         // error: 
	//_ = C2(c)         // error: 
	var c1a chan<- int
	var c2a <-chan int
	var c1b C1
	var c2b C2
	
	var tc1a = reflect.TypeOf(c1a)
	var tc2a = reflect.TypeOf(c2a)
	var tc1b = reflect.TypeOf(c1b)
	var tc2b = reflect.TypeOf(c2b)
	
	var t = reflect.TypeOf(c)
	println(t.ConvertibleTo(tc1a)) // true
	println(t.ConvertibleTo(tc2a)) // true
	println(t.ConvertibleTo(tc1b)) // true, but the above corresponding line compiles error
	println(t.ConvertibleTo(tc2b)) // true, but the above corresponding line compiles error
}

Another bug is mentioned a below comment: #29469 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions