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

Leverage type information provided by type assertions #210

Open
mlevesquedion opened this issue Dec 3, 2020 · 0 comments
Open

Leverage type information provided by type assertions #210

mlevesquedion opened this issue Dec 3, 2020 · 0 comments

Comments

@mlevesquedion
Copy link
Contributor

mlevesquedion commented Dec 3, 2020

This issue is related to #161.

Consider the following test case:

func TestPanicTypeAssertSource(i interface{}) {
	s := i.(core.Source)
	_ = s
	// The dominating type assertion would panic if i were not a source type.
	core.Sink(i) // TODO(210) want "a source has reached a sink"
}

Clearly, the only way that the call to core.Sink can be reached is if i holds a value of type core.Source. The above code is therefore unsafe.

The following case is more ambiguous, and currently we do not expect a report to be produced:

func TestOkayTypeAssert(i interface{}) {
	s, ok := i.(core.Source)
	_, _ = s, ok
	// The dominating type assertion will not panic.
	core.Sink(i)
}

Since the , ok form is used, it is possible that the type assertion failed and that i is in fact safe to sink. However, there is certainly a possibility that i contains a value of type core.Source, and therefore this code should perhaps be considered unsafe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant