Skip to content

Commit

Permalink
Fixed array out of bounds in CallResolver (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored Sep 1, 2021
1 parent a915f63 commit a7c378e
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,7 @@ private List<FunctionDeclaration> resolveWithImplicitCast(
private List<FunctionDeclaration> resolveWithImplicitCastFunc(CallExpression call) {
assert lang != null;
List<FunctionDeclaration> initialInvocationCandidates =
lang.getScopeManager().resolveFunctionStopScopeTraversalOnDefinition(call).stream()
// .filter(f -> !f.isImplicit())
.collect(Collectors.toList());
new ArrayList<>(lang.getScopeManager().resolveFunctionStopScopeTraversalOnDefinition(call));
return resolveWithImplicitCast(call, initialInvocationCandidates);
}

Expand All @@ -909,15 +907,18 @@ private void checkMostCommonImplicitCast(
List<CastExpression> implicitCasts, List<CastExpression> implicitCastTargets) {
for (int i = 0; i < implicitCasts.size(); i++) {
CastExpression currentCast = implicitCasts.get(i);
CastExpression otherCast = implicitCastTargets.get(i);
if (currentCast != null && otherCast != null && !(currentCast.equals(otherCast))) {
// If we have multiple function targets with different implicit casts we have an
// ambiguous call and we can't have a single cast
CastExpression contradictoryCast = new CastExpression();
contradictoryCast.setImplicit(true);
contradictoryCast.setCastType(UnknownType.getUnknownType());
contradictoryCast.setExpression(currentCast.getExpression());
implicitCasts.set(i, contradictoryCast);

if(i < implicitCastTargets.size()) {
CastExpression otherCast = implicitCastTargets.get(i);
if (currentCast != null && otherCast != null && !(currentCast.equals(otherCast))) {
// If we have multiple function targets with different implicit casts we have an
// ambiguous call and we can't have a single cast
CastExpression contradictoryCast = new CastExpression();
contradictoryCast.setImplicit(true);
contradictoryCast.setCastType(UnknownType.getUnknownType());
contradictoryCast.setExpression(currentCast.getExpression());
implicitCasts.set(i, contradictoryCast);
}
}
}
}
Expand Down

0 comments on commit a7c378e

Please sign in to comment.