Avoid throwing unchecked exceptions
Make `ResolvedCall.getValueArgumentsByIndex` return null instead of throwing an InvalidStateException when resolving invalid arguments. Invalid arguments are a user error (the user specified the invalid arguments in their code), not a program error.
This commit is contained in:
@@ -99,6 +99,9 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, /*isGetter = */ false);
|
||||
|
||||
List<ResolvedValueArgument> arguments = resolvedCall.getValueArgumentsByIndex();
|
||||
if (arguments == null) {
|
||||
throw new IllegalStateException("Failed to arrange value arguments by index");
|
||||
}
|
||||
ResolvedValueArgument lastArgument = arguments.get(arguments.size() - 1);
|
||||
assert lastArgument instanceof ExpressionValueArgument: "Last argument of array-like setter must be ExpressionValueArgument";
|
||||
|
||||
|
||||
+3
@@ -159,6 +159,9 @@ public class CallArgumentTranslator extends AbstractTranslator {
|
||||
|
||||
List<JsExpression> result = new ArrayList<JsExpression>(valueParameters.size());
|
||||
List<ResolvedValueArgument> valueArgumentsByIndex = resolvedCall.getValueArgumentsByIndex();
|
||||
if (valueArgumentsByIndex == null) {
|
||||
throw new IllegalStateException("Failed to arrange value arguments by index");
|
||||
}
|
||||
List<JsExpression> argsBeforeVararg = null;
|
||||
for (ValueParameterDescriptor parameterDescriptor : valueParameters) {
|
||||
ResolvedValueArgument actualArgument = valueArgumentsByIndex.get(parameterDescriptor.getIndex());
|
||||
|
||||
+5
-1
@@ -148,7 +148,11 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio
|
||||
|
||||
@NotNull
|
||||
private TemporaryVariable createAliasForArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
ResolvedValueArgument actualArgument = resolvedCall.getValueArgumentsByIndex().get(parameterDescriptor.getIndex());
|
||||
List<ResolvedValueArgument> actualArguments = resolvedCall.getValueArgumentsByIndex();
|
||||
if (actualArguments == null) {
|
||||
throw new IllegalStateException("Failed to arrange value arguments by index");
|
||||
}
|
||||
ResolvedValueArgument actualArgument = actualArguments.get(parameterDescriptor.getIndex());
|
||||
JsExpression translatedArgument = translateArgument(actualArgument);
|
||||
TemporaryVariable aliasForArgument = context().declareTemporary(translatedArgument);
|
||||
context().addStatementToCurrentBlock(aliasForArgument.assignmentExpression().makeStmt());
|
||||
|
||||
Reference in New Issue
Block a user