New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused: wrong result #199

Closed
Konstantin8105 opened this Issue Oct 5, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@Konstantin8105

Konstantin8105 commented Oct 5, 2017

Input data:

package main

import "unsafe"
import "reflect"

type pthread_attr_t [56]byte

func (self *pthread_attr_t) cast(t reflect.Type) reflect.Value {
	return reflect.NewAt(t, unsafe.Pointer(&self[0]))
}

Output of unused program:

exit.go:6:6: type pthread_attr_t is unused (U1000)
@Konstantin8105

This comment has been minimized.

Show comment
Hide comment
@Konstantin8105

Konstantin8105 Oct 5, 2017

Please clarify - that is happen because that func cast is not used in func main.

Konstantin8105 commented Oct 5, 2017

Please clarify - that is happen because that func cast is not used in func main.

@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur

dmitshur Oct 5, 2017

Contributor

The program you provided is not valid, it's missing main function.

Given the following program with a main, unused correctly reports that type pthread_attr_t is unused:

package main

import "unsafe"
import "reflect"

type pthread_attr_t [56]byte

func (self *pthread_attr_t) cast(t reflect.Type) reflect.Value {
	return reflect.NewAt(t, unsafe.Pointer(&self[0]))
}

func main() {}

The following program does not produce any output from unused:

package main

import "unsafe"
import "reflect"

type pthread_attr_t [56]byte

func (self *pthread_attr_t) cast(t reflect.Type) reflect.Value {
	return reflect.NewAt(t, unsafe.Pointer(&self[0]))
}

func main() {
	var x pthread_attr_t
	x.cast(reflect.TypeOf(0))
}

Because both pthread_attr_t and its cast method are used.

What's this issue about?

Contributor

dmitshur commented Oct 5, 2017

The program you provided is not valid, it's missing main function.

Given the following program with a main, unused correctly reports that type pthread_attr_t is unused:

package main

import "unsafe"
import "reflect"

type pthread_attr_t [56]byte

func (self *pthread_attr_t) cast(t reflect.Type) reflect.Value {
	return reflect.NewAt(t, unsafe.Pointer(&self[0]))
}

func main() {}

The following program does not produce any output from unused:

package main

import "unsafe"
import "reflect"

type pthread_attr_t [56]byte

func (self *pthread_attr_t) cast(t reflect.Type) reflect.Value {
	return reflect.NewAt(t, unsafe.Pointer(&self[0]))
}

func main() {
	var x pthread_attr_t
	x.cast(reflect.TypeOf(0))
}

Because both pthread_attr_t and its cast method are used.

What's this issue about?

@Konstantin8105

This comment has been minimized.

Show comment
Hide comment
@Konstantin8105

Konstantin8105 commented Oct 6, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment