-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Go: Add tests for model inheritance and fix bug in promoted methods #17505
Conversation
64baf65
to
5a1bada
Compare
pack: codeql/go-all | ||
extensible: sourceModel | ||
data: | ||
- ["github.com/nonexistent/test", "I1", False, "Source", "", "", "ReturnValue", "remote", "manual"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting to note that with subtypes = false we actually do model a struct that embeds I1 here. I think we shouldn't (not to fix here, a note for the future)
@@ -0,0 +1,40 @@ | |||
invalidModelRow | |||
paths | |||
| test.go:8:7:8:16 | call to Source | test.go:10:9:10:9 | y | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Probably good to note these in the corresponding QL files in the manner we would with $ MISSING
and similar if this was an inline-expectations test): I believe these are all good results except for the cases that shadow the relevant methods which are FPs.
@@ -0,0 +1,10 @@ | |||
invalidModelRow | |||
paths | |||
| test.go:14:7:14:16 | call to Source | test.go:16:9:16:9 | y | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again noting expectations to cross-check: I think the embedding result is unexpected
@@ -0,0 +1,22 @@ | |||
invalidModelRow | |||
paths | |||
| test.go:14:7:14:16 | call to Source | test.go:16:9:16:9 | y | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And these are all good except for the overriding cases which are FPs
@@ -0,0 +1,10 @@ | |||
invalidModelRow | |||
paths | |||
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to I1, the embedding result is bad
@@ -0,0 +1,10 @@ | |||
invalidModelRow | |||
paths | |||
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently subtypes = true for a non-interface does nothing; if it did anything in the future it would be to include embeddings, which we do here by accident
t.Sink(y) | ||
} | ||
|
||
func TestStructEmbeddingAndOverridingS2(t test.StructEmbeddingAndOverridingS2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest one more case to include: interface-in-interface embedding, which is a slightly different beast to X-in-struct embedding, where X may be an interface or a struct, since it doesn't create a field
5a1bada
to
c53b55b
Compare
This is redundant given that we test for paths, and for a path we need the source, step and sink methods to be modeled.
c53b55b
to
b0caaba
Compare
@smowton I've revamped the tests to be inline expectations tests. It's just so much easier to deal with. I've added the case you suggested. I've fixed a bug that was causing us to promote methods that shouldn't have been promoted because the receiver type already has a method with the same name. Even with this bug fixed, I agree that the current behaviour of our MaD tests around promoted methods should be changed. The model for |
Suggest change the PR title and description before merging, and add a change note, since it now actually fixes a bug. |
@@ -0,0 +1,89 @@ | |||
package main | |||
|
|||
import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend using the SPURIOUS attribute throughout (and if applicable MISSING, though I don't think there are any missing results) to identify what ought to be fixed
DCA with the normal source suite didn't show any changes. I also ran it with the suite @smowton made recently of repos which exercise our models more (which is much larger at 129 repos). This showed alert losses in 7 repos. I looked into them. They almost all seem to relate to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the spurious annotations are correct, though it's hard to be 100% certain. Once the fixes start to roll in it'll become clear if we see anything other than the expected spurious -> absent transitions.
These tests show several things:
getACall()
in QL models is overly broad: see from theql_S1
comments that by modelingS1
we also match calls toI1
, which is an interface thatS1
implements. This is not what users would expect.This PR also fixes a bug where methods of an embedded field were promoted when they shouldn't have been (because the type already has a method of that name).