Skip to content

Commit eea96a5

Browse files
committed
Fix effective publicness of protected private and protected internal
1 parent f715445 commit eea96a5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

csharp/ql/src/semmle/code/csharp/Member.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,32 @@ class Modifiable extends Declaration, @modifiable {
9696
/** Holds if this declaration is `async`. */
9797
predicate isAsync() { this.hasModifier("async") }
9898

99+
private predicate isReallyPrivate() { this.isPrivate() and not this.isProtected() }
100+
99101
/**
100102
* Holds if this declaration is effectively `private` (either directly or
101103
* because one of the enclosing types is `private`).
102104
*/
103105
predicate isEffectivelyPrivate() {
104-
this.isPrivate() or
105-
this.getDeclaringType+().isPrivate() or
106+
this.isReallyPrivate() or
107+
this.getDeclaringType+().(Modifiable).isReallyPrivate() or
106108
this.(Virtualizable).getExplicitlyImplementedInterface().isEffectivelyPrivate()
107109
}
108110

111+
private predicate isReallyInternal() {
112+
this.isInternal() and not this.isProtected()
113+
or
114+
this.isPrivate() and this.isProtected()
115+
}
116+
109117
/**
110118
* Holds if this declaration is effectively `internal` (either directly or
111119
* because one of the enclosing types is `internal`).
112120
*/
113121
predicate isEffectivelyInternal() {
114-
this.isInternal() or
115-
this.getDeclaringType+().isInternal() or
116-
this.(Virtualizable).getExplicitlyImplementedInterface().isInternal()
122+
this.isReallyInternal() or
123+
this.getDeclaringType+().(Modifiable).isReallyInternal() or
124+
this.(Virtualizable).getExplicitlyImplementedInterface().isEffectivelyInternal()
117125
}
118126

119127
/**

csharp/ql/test/library-tests/modifiers/Effectively.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
| Modifiers.cs:68:14:68:15 | M1 | internal |
2828
| Modifiers.cs:71:18:71:19 | C2 | public |
2929
| Modifiers.cs:73:17:73:18 | M1 | internal |
30+
| Modifiers.cs:75:32:75:33 | M2 | internal |
31+
| Modifiers.cs:76:33:76:34 | M3 | public |

0 commit comments

Comments
 (0)