Skip to content

Commit 6e428d5

Browse files
committed
Fix bug where some methods were inappropriately promoted
1 parent 0255edf commit 6e428d5

File tree

2 files changed

+15
-15
lines changed
  • go/ql
    • lib/semmle/go
    • test/library-tests/semmle/go/dataflow/ExternalFlowInheritance

2 files changed

+15
-15
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ class NamedType extends @namedtype, CompositeType {
10001000
s.hasOwnField(_, _, embedded, true) and
10011001
// ensure `m` can be promoted
10021002
not s.hasOwnField(_, m, _, _) and
1003-
not exists(Method m2 | m2.getReceiverType() = this and m2.getName() = m)
1003+
not exists(Method m2 | m2.getReceiverBaseType() = this and m2.getName() = m)
10041004
|
10051005
// If S contains an embedded field T, the method set of S includes promoted methods with receiver T
10061006
result = embedded.getMethod(m)

go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,83 @@ import (
77
func TestI1(t test.I1) {
88
x := t.Source()
99
y := t.Step(x)
10-
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t]
10+
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t]
1111
}
1212

1313
func TestI2(t test.I2) {
1414
x := t.Source()
1515
y := t.Step(x)
16-
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
16+
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t]
1717
}
1818

1919
func TestS1(t test.S1) {
2020
x := t.Source()
2121
y := t.Step(x)
22-
t.Sink(y) // $ I1[t] IEmbedI1[t] S1[f] S1[t] SEmbedI1[t] SImplEmbedI1[t]
22+
t.Sink(y) // $ I1[t] IEmbedI1[t] S1[f] S1[t] SEmbedI1[t]
2323
}
2424

2525
func TestS2(t test.S2) {
2626
x := t.Source()
2727
y := t.Step(x)
28-
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
28+
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t]
2929
}
3030

3131
func TestSEmbedI1(t test.SEmbedI1) {
3232
x := t.Source()
3333
y := t.Step(x)
34-
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t]
34+
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t]
3535
}
3636

3737
func TestSEmbedI2(t test.SEmbedI2) {
3838
x := t.Source()
3939
y := t.Step(x)
40-
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
40+
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t]
4141
}
4242

4343
func TestIEmbedI1(t test.IEmbedI1) {
4444
x := t.Source()
4545
y := t.Step(x)
46-
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t]
46+
t.Sink(y) // $ I1[f] I1[t] IEmbedI1[t] SEmbedI1[t]
4747
}
4848

4949
func TestIEmbedI2(t test.IEmbedI2) {
5050
x := t.Source()
5151
y := t.Step(x)
52-
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
52+
t.Sink(y) // $ I1[t] I2[f] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t]
5353
}
5454

5555
func TestSImplEmbedI1(t test.SImplEmbedI1) {
5656
x := t.Source()
5757
y := t.Step(x)
58-
t.Sink(y) // $ I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t]
58+
t.Sink(y) // $ I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t]
5959
}
6060

6161
func TestSImplEmbedI2(t test.SImplEmbedI2) {
6262
x := t.Source()
6363
y := t.Step(x)
64-
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
64+
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI2[t]
6565
}
6666

6767
func TestSEmbedS1(t test.SEmbedS1) {
6868
x := t.Source()
6969
y := t.Step(x)
70-
t.Sink(y) // $ I1[t] IEmbedI1[t] S1[f] S1[t] SEmbedI1[t] SImplEmbedI1[t]
70+
t.Sink(y) // $ I1[t] IEmbedI1[t] S1[f] S1[t] SEmbedI1[t]
7171
}
7272

7373
func TestSEmbedS2(t test.SEmbedS2) {
7474
x := t.Source()
7575
y := t.Step(x)
76-
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t]
76+
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t]
7777
}
7878

7979
func TestSImplEmbedS1(t test.SImplEmbedS1) {
8080
x := t.Source()
8181
y := t.Step(x)
82-
t.Sink(y) // $ I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedI1[t] SImplEmbedS1[t]
82+
t.Sink(y) // $ I1[t] IEmbedI1[t] SEmbedI1[t] SImplEmbedS1[t]
8383
}
8484

8585
func TestSImplEmbedS2(t test.SImplEmbedS2) {
8686
x := t.Source()
8787
y := t.Step(x)
88-
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedI1[t] SImplEmbedI2[t] SImplEmbedS2[t]
88+
t.Sink(y) // $ I1[t] I2[t] IEmbedI1[t] IEmbedI2[t] SEmbedI1[t] SEmbedI2[t] SImplEmbedS2[t]
8989
}

0 commit comments

Comments
 (0)