Skip to content

Commit

Permalink
Fixed implicit item bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCockx committed Nov 20, 2023
1 parent db3e4b3 commit 97d48c8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
22 changes: 4 additions & 18 deletions rosetta-lang/model/RosettaExpression.xcore
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ class ListLiteral extends RosettaExpression {
abstract class RosettaReference extends RosettaExpression {
}

class RosettaSymbolReference extends RosettaReference, HasGeneratedInput {
class RosettaSymbolReference extends RosettaReference {
refers RosettaSymbol symbol

boolean explicitArguments
contains RosettaExpression[] rawArgs

contains RosettaImplicitVariable implicitArgument
boolean implicitVariableIsInContext
contains RosettaExpression implicitArgument

op RosettaExpression[] getArgs() {
if (!explicitArguments && symbol instanceof RosettaCallableWithArgs && (symbol as RosettaCallableWithArgs).numberOfParameters == 1) {
if (!explicitArguments && implicitVariableIsInContext && symbol instanceof RosettaCallableWithArgs && (symbol as RosettaCallableWithArgs).numberOfParameters == 1) {
if (implicitArgument === null) {
val def = ExpressionFactory.eINSTANCE.createRosettaImplicitVariable();
def.setName("item");
Expand All @@ -136,21 +137,6 @@ class RosettaSymbolReference extends RosettaReference, HasGeneratedInput {
}
return rawArgs
}
op void setGeneratedInputIfAbsent(RosettaExpression e) {
if (e === null) {
if (generatedInputWasSet) {
implicitArgument = null
generatedInputWasSet = false
}
} else {
if (!generatedInputWasSet) {
generatedInputWasSet = true
}
}
}
op boolean needsGeneratedInput() {
false
}
}

class RosettaImplicitVariable extends RosettaReference, RosettaNamed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.regnosys.rosetta.rosetta.expression.ListLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaConditionalExpression;
import com.regnosys.rosetta.rosetta.expression.RosettaStringLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaSymbolReference;
import com.regnosys.rosetta.utils.ImplicitVariableUtil;

/**
Expand Down Expand Up @@ -43,6 +44,8 @@ public void setDerivedState(EObject obj) {
this.setDefaultElseToEmpty((RosettaConditionalExpression)obj);
} else if (obj instanceof JoinOperation) {
this.setDefaultJoinSeparator((JoinOperation)obj);
} else if (obj instanceof RosettaSymbolReference) {
this.setImplicitVariableInContextOfSymbolReference((RosettaSymbolReference)obj);
}
if (obj instanceof HasGeneratedInput) {
this.setDefaultInput((HasGeneratedInput)obj);
Expand All @@ -62,6 +65,8 @@ public void removeDerivedState(EObject obj) {
this.discardDefaultElse((RosettaConditionalExpression)obj);
} else if (obj instanceof JoinOperation) {
this.discardDefaultJoinSeparator((JoinOperation)obj);
} else if (obj instanceof RosettaSymbolReference) {
this.discardImplicitVariableInContextOfSymbolReference((RosettaSymbolReference)obj);
}
if (obj instanceof HasGeneratedInput) {
this.discardDefaultInput((HasGeneratedInput)obj);
Expand Down Expand Up @@ -118,4 +123,16 @@ private void discardDefaultJoinSeparator(JoinOperation expr) {
}
}
}

private void setImplicitVariableInContextOfSymbolReference(RosettaSymbolReference expr) {
if (implicitVariableUtil.implicitVariableExistsInContext(expr)) {
expr.setImplicitVariableIsInContext(true);
}
}
private void discardImplicitVariableInContextOfSymbolReference(RosettaSymbolReference expr) {
if (expr.isImplicitVariableIsInContext()) {
expr.setImplicitVariableIsInContext(false);
expr.setImplicitArgument(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class RosettaTransientValueService extends DefaultTransientValueService {
private EStructuralFeature generatedInputWasSetFeature = ExpressionPackage.eINSTANCE.getHasGeneratedInput_GeneratedInputWasSet();
private EStructuralFeature implicitVariableIsInContextFeature = ExpressionPackage.eINSTANCE.getRosettaSymbolReference_ImplicitVariableIsInContext();

@Override
public boolean isCheckElementsIndividually(EObject owner, EStructuralFeature feature) {
Expand All @@ -22,7 +23,7 @@ public boolean isTransient(EObject owner, EStructuralFeature feature, int index)
if (super.isTransient(owner, feature, index)) {
return true;
}
if (feature.equals(generatedInputWasSetFeature)) {
if (feature.equals(generatedInputWasSetFeature) || feature.equals(implicitVariableIsInContextFeature)) {
return true;
}
Object value = owner.eGet(feature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ class RosettaParsingTest {
model.elements.head as Function => [
operations.head.expression as RosettaSymbolReference => [
assertTrue(explicitArguments)
assertFalse(needsGeneratedInput)
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,22 @@ class RosettaValidatorTest implements RosettaIssueCodes {

@Inject extension ValidationTestHelper
@Inject extension ModelHelper

@Test
def void testCannotCallFuncWithoutInput() {
val model = '''
func Foo:
inputs: a int (1..1)
output: result int (1..1)
set result:
Foo
'''.parseRosetta

model.assertError(ROSETTA_SYMBOL_REFERENCE, null,
"Invalid number of arguments. Expecting 1 but passed 0."
)
}

@Test
def void testOrderDoesNotMatter() {
val model1 = '''
Expand Down

0 comments on commit 97d48c8

Please sign in to comment.