Skip to content
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
Closed

unused: wrong result #199

Konstantin8105 opened this issue Oct 5, 2017 · 3 comments
Labels
invalid User error and other non-issues

Comments

@Konstantin8105
Copy link

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
Copy link
Author

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

@dmitshur
Copy link
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
Copy link
Author

Thanks

@dominikh dominikh added the invalid User error and other non-issues label Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid User error and other non-issues
Projects
None yet
Development

No branches or pull requests

3 participants