Skip to content

Commit

Permalink
fixes #1492 crash in guards
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLethbridge committed Sep 10, 2019
1 parent fe0fadb commit 561de78
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cruise.umple/src/UmpleInternalParser_CodeStateMachine.ump
Expand Up @@ -1582,7 +1582,7 @@ class UmpleInternalParser
private Token getExpressionOperator(Token expression, Integer startIndex)
{
Integer operatorPosition = startIndex + OPERATOR_POSITION;
if (operatorPosition < expression.getSubTokens().size())
if (operatorPosition < expression.getSubTokens().size()-1)
{
Token operator = expression.getSubToken(operatorPosition);
String operatorName = operator.getName();
Expand Down
24 changes: 24 additions & 0 deletions cruise.umple/test/cruise/umple/compiler/DuplicateGuards.ump
@@ -0,0 +1,24 @@
class OtherClass {
* -> 1 Another ;
Integer row;
Integer row2;
}

class Another {
Integer junk;
}

class Statemachine {
* -> 1 OtherClass other;
Boolean cond;
sm {
s1 {
event1[other.another.junk == 3] -> s3;
event1[other.another.junk == 3] -> s1;
event1[cond && other.row > 4] -> s2;
event1[cond && other.row == 3] -> s3;
event1[cond && other.row == 3] -> s1;
}
s3 {}
}
}
Expand Up @@ -113,6 +113,14 @@ public void handleBangInGuard2()
Assert.assertEquals("if (((getFlag()!=getFlag())||(getFlag()||getFlag())))\n{\n {0}\n}", gen.translate("on", t3.getGuard()));
Assert.assertEquals("if ((!(!getFlag()&&getX())&&(getX()||getX())))\n{\n {0}\n}", gen.translate("on", t4.getGuard()));
}

// Issue 1492
@Test
public void verifyDuplicateGuards()
{
assertHasWarning("DuplicateGuards.ump",0,70);
assertHasWarning("DuplicateGuards.ump",1,70);
}

// Issue 796
@Test
Expand Down Expand Up @@ -2723,6 +2731,10 @@ private void assertNoWarnings(String filename)
assertHasWarning(filename, -1, -1, null);
}

private void assertHasWarning(String filename, int expectedWarningIndex, int expectedError) {
assertHasWarning(filename, expectedWarningIndex, expectedError, null);
}

private void assertHasWarning(String filename, int expectedWarningIndex, int expectedError, Position expectedPosition)
{
File file = new File(pathToInput, filename);
Expand Down Expand Up @@ -2755,7 +2767,9 @@ private void assertHasWarning(String filename, int expectedWarningIndex, int exp
Assert.assertNotNull(parser.getParseResult().getErrorMessage(expectedWarningIndex));
Assert.assertEquals(expectedError, parser.getParseResult().getErrorMessage(expectedWarningIndex).getErrorType().getErrorCode());
System.out.println(">>" + parser.getParseResult().getErrorMessage(expectedWarningIndex).getPosition().getOffset());
Assert.assertEquals(expectedPosition, parser.getParseResult().getErrorMessage(expectedWarningIndex).getPosition());
if (expectedPosition != null) {
Assert.assertEquals(expectedPosition, parser.getParseResult().getErrorMessage(expectedWarningIndex).getPosition());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions cruise.umplificator/src/Master.ump
Expand Up @@ -11,6 +11,7 @@ The following instructs the system to inject comments on every class point to th
@outputumplesource
*/
strictness allow 30;
strictness allow 31;
strictness allow 1006;
strictness allow 1007;
strictness allow 1008;
Expand Down

0 comments on commit 561de78

Please sign in to comment.