Skip to content

Commit

Permalink
fix arguments not checked for remote calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Mar 2, 2022
1 parent 9eaa981 commit 040fe7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Core/src/main/java/prompto/statement/MethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public IType check(Context context, boolean updateSelectorParent) {
}
}
}

public ArgumentList makeArguments(Context context) {
MethodFinder finder = new MethodFinder(context, this);
IMethodDeclaration declaration = finder.findBest(false);
return makeArguments(context, declaration);
}

private void checkAbstractOnly(Context context, IMethodDeclaration declaration) {
if(declaration.isReference()) // parameter or variable populated from a method call
Expand Down
16 changes: 9 additions & 7 deletions Core/src/main/java/prompto/statement/RemoteCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public IType check(Context context) {
IType type = resolveAndCheck(context);
if(!(resolved instanceof MethodCall))
context.getProblemListener().reportIllegalRemoteCall(this, resolved.toString());
final Context local = context.newChildContext();
ArgumentList arguments = ((MethodCall)resolved).makeArguments(context);
arguments.forEach(arg -> arg.check(context));
Context local = context.newChildContext();
if(resultName!=null)
local.registerValue(new Variable(resultName, type));
if(arguments!=null)
arguments.forEach(arg -> arg.check(context));
andThen.check(local, VoidType.instance());
return VoidType.instance();
}
Expand Down Expand Up @@ -108,17 +108,19 @@ public void declare(Transpiler transpiler) {
else
transpiler.require("Remote");
transpiler.require("RemoteRunner");
IType type = resolveAndCheck(transpiler.getContext());
if(!(resolved instanceof MethodCall))
transpiler.getContext().getProblemListener().reportIllegalRemoteCall(this, resolved.toString());
ArgumentList arguments = ((MethodCall)resolved).makeArguments(transpiler.getContext());
arguments.forEach(arg -> arg.declare(transpiler, null));
final Transpiler local = transpiler.newChildTranspiler();
if(resultName!=null) {
IType type = resolveAndCheck(local.getContext());
type.declare(local);
local.getContext().registerValue(new Variable(resultName, type));
}
if(arguments!=null)
arguments.forEach(arg -> arg.declare(local, null));
andThen.declare(local);
}

@Override
public boolean transpile(Transpiler transpiler) {
resolveAndCheck(transpiler.getContext());
Expand Down
12 changes: 8 additions & 4 deletions Core/src/main/java/prompto/type/CategoryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,19 @@ private void readJSONField(Context context, IInstance instance, String fieldName

private IType readJSONFieldType(Context context, Identifier fieldId, JsonNode fieldData) {
AttributeDeclaration attribute = context.getRegisteredDeclaration(AttributeDeclaration.class, fieldId);
IType fieldType = attribute.getType(context);
IType fieldType = attribute.getType(context).resolve(context, null);
return checkDerivedType(context, fieldType, fieldData);
}

private IType checkDerivedType(Context context, IType fieldType, JsonNode fieldData) {
if(fieldType instanceof CategoryType) {
if(fieldData.isObject() && fieldData.has("type"))
return new CategoryType(new Identifier(fieldData.get("type").asText()));
else {
if(fieldData.isObject() && fieldData.has("type")) {
String typeName = fieldData.get("type").asText();
if(typeName.equals(fieldType.getTypeName()))
return fieldType;
else
return new CategoryType(new Identifier(typeName)).resolve(context, null);
} else {
IDeclaration declaration = getDeclaration(context, fieldType.getTypeNameId());
return declaration.getType(context);
}
Expand Down
7 changes: 7 additions & 0 deletions Core/src/main/java/prompto/value/ContextualExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public ResultInfo compile(Context context, MethodInfo method, Flags flags) {
return expression.compile(this.calling, method, flags);
}


@Override
public void declare(Transpiler transpiler) {
transpiler = transpiler.newChildTranspiler(this.calling);
this.expression.declare(transpiler);
}

@Override
public boolean transpile(Transpiler transpiler) {
transpiler = transpiler.newChildTranspiler(this.calling);
Expand Down

0 comments on commit 040fe7e

Please sign in to comment.