Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8922b0

Browse files
committed
Java: Support wildcards for functional interfaces.
1 parent 0caee16 commit b8922b0

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

java/ql/src/utils/model-generator/internal/CaptureTypeBasedSummaryModels.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,29 @@ private class Function extends ParameterizedType {
110110

111111
/**
112112
* Gets the parameter type of `this` function at position `position`.
113+
* Note that functions are contravariant in their parameter types.
113114
*/
114115
Type getParameterType(int position) {
115-
fi.getRunMethod().getParameterType(position) = getTypeReplacement(result)
116+
exists(Type t | fi.getRunMethod().getParameterType(position) = getTypeReplacement(t) |
117+
(
118+
result = t or
119+
result = t.(Wildcard).getLowerBound().getType()
120+
)
121+
)
116122
}
117123

118124
/**
119125
* Gets the return type of `this` function.
126+
* Note that functions are covariant in their return type.
120127
*/
121-
Type getReturnType() { fi.getRunMethod().getReturnType() = getTypeReplacement(result) }
128+
Type getReturnType() {
129+
exists(Type t | fi.getRunMethod().getReturnType() = getTypeReplacement(t) |
130+
(
131+
result = t or
132+
result = t.(Wildcard).getUpperBound().getType()
133+
)
134+
)
135+
}
122136
}
123137

124138
/**

0 commit comments

Comments
 (0)