Skip to content

Commit

Permalink
Merge branch '411-bug-forever-inside-loop' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Bug Forever Inside Loop"

Closes #411

See merge request se2/litterbox!552
  • Loading branch information
gofraser committed Aug 25, 2022
2 parents ae36d5a + 47a58a6 commit 90a91ed
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void visit(ActorDefinition actor) {

@Override
public void visit(UntilStmt node) {
loopStack.push(node);
checkPosition(node);
loopStack.push(node);
visitChildren(node);
loopStack.pop();
}
Expand Down
268 changes: 268 additions & 0 deletions src/test/fixtures/bugpattern/foreverInsideLoopBlockBeforeUntil.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
{
"targets": [
{
"isStage": true,
"name": "Stage",
"variables": {
"`jEk@4|i[#Fk?(8x)AV.-my variable": [
"my variable",
0
]
},
"lists": {},
"broadcasts": {},
"blocks": {},
"comments": {},
"currentCostume": 0,
"costumes": [
{
"name": "backdrop1",
"dataFormat": "svg",
"assetId": "cd21514d0531fdffb22204e0ec5ed84a",
"md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg",
"rotationCenterX": 240,
"rotationCenterY": 180
}
],
"sounds": [
{
"name": "pop",
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
"dataFormat": "wav",
"format": "",
"rate": 48000,
"sampleCount": 1124,
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
}
],
"volume": 100,
"layerOrder": 0,
"tempo": 60,
"videoTransparency": 50,
"videoState": "on",
"textToSpeechLanguage": null
},
{
"isStage": false,
"name": "Sprite1",
"variables": {},
"lists": {},
"broadcasts": {},
"blocks": {
";os!m|z0$,|aYto~BN/}": {
"opcode": "event_whenflagclicked",
"next": "g]x*xJwy{TiqJ$^LQjGx",
"parent": null,
"inputs": {},
"fields": {},
"shadow": false,
"topLevel": true,
"x": 579,
"y": 221
},
"g]x*xJwy{TiqJ$^LQjGx": {
"opcode": "looks_say",
"next": "bJ@L`[ct2wE%JFc$:Qew",
"parent": ";os!m|z0$,|aYto~BN/}",
"inputs": {
"MESSAGE": [
1,
[
10,
"Hello!"
]
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"bJ@L`[ct2wE%JFc$:Qew": {
"opcode": "control_repeat_until",
"next": null,
"parent": "g]x*xJwy{TiqJ$^LQjGx",
"inputs": {
"CONDITION": [
2,
")VsoB6aDHc2pMn*QFaR5"
],
"SUBSTACK": [
2,
"6An!-Zok/I-6^D!mp9NB"
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
")VsoB6aDHc2pMn*QFaR5": {
"opcode": "sensing_touchingobject",
"next": null,
"parent": "bJ@L`[ct2wE%JFc$:Qew",
"inputs": {
"TOUCHINGOBJECTMENU": [
1,
"PN#/YT#Wxkhf-[t8/568"
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"PN#/YT#Wxkhf-[t8/568": {
"opcode": "sensing_touchingobjectmenu",
"next": null,
"parent": ")VsoB6aDHc2pMn*QFaR5",
"inputs": {},
"fields": {
"TOUCHINGOBJECTMENU": [
"_mouse_",
null
]
},
"shadow": true,
"topLevel": false
},
"6An!-Zok/I-6^D!mp9NB": {
"opcode": "sensing_askandwait",
"next": "JIrm^eyI=f9b*CIsmAOM",
"parent": "bJ@L`[ct2wE%JFc$:Qew",
"inputs": {
"QUESTION": [
1,
[
10,
"What's your name?"
]
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"JIrm^eyI=f9b*CIsmAOM": {
"opcode": "control_repeat_until",
"next": null,
"parent": "6An!-Zok/I-6^D!mp9NB",
"inputs": {
"CONDITION": [
2,
"bc9/~lCf1):7akf,ou)/"
],
"SUBSTACK": [
2,
"9z}l}j5}0S.BjQA~5bH6"
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"bc9/~lCf1):7akf,ou)/": {
"opcode": "operator_contains",
"next": null,
"parent": "JIrm^eyI=f9b*CIsmAOM",
"inputs": {
"STRING1": [
1,
[
10,
"apple"
]
],
"STRING2": [
1,
[
10,
"a"
]
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"9z}l}j5}0S.BjQA~5bH6": {
"opcode": "control_forever",
"next": null,
"parent": "JIrm^eyI=f9b*CIsmAOM",
"inputs": {
"SUBSTACK": [
2,
"1%XXl]n?J6sL]L~f6|qR"
]
},
"fields": {},
"shadow": false,
"topLevel": false
},
"1%XXl]n?J6sL]L~f6|qR": {
"opcode": "motion_movesteps",
"next": null,
"parent": "9z}l}j5}0S.BjQA~5bH6",
"inputs": {
"STEPS": [
1,
[
4,
"10"
]
]
},
"fields": {},
"shadow": false,
"topLevel": false
}
},
"comments": {},
"currentCostume": 0,
"costumes": [
{
"name": "costume1",
"bitmapResolution": 1,
"dataFormat": "svg",
"assetId": "bcf454acf82e4504149f7ffe07081dbc",
"md5ext": "bcf454acf82e4504149f7ffe07081dbc.svg",
"rotationCenterX": 48,
"rotationCenterY": 50
},
{
"name": "costume2",
"bitmapResolution": 1,
"dataFormat": "svg",
"assetId": "0fb9be3e8397c983338cb71dc84d0b25",
"md5ext": "0fb9be3e8397c983338cb71dc84d0b25.svg",
"rotationCenterX": 46,
"rotationCenterY": 53
}
],
"sounds": [
{
"name": "Meow",
"assetId": "83c36d806dc92327b9e7049a565c6bff",
"dataFormat": "wav",
"format": "",
"rate": 48000,
"sampleCount": 40682,
"md5ext": "83c36d806dc92327b9e7049a565c6bff.wav"
}
],
"volume": 100,
"layerOrder": 1,
"visible": true,
"x": 0,
"y": 0,
"size": 100,
"direction": 90,
"draggable": false,
"rotationStyle": "all around"
}
],
"monitors": [],
"extensions": [],
"meta": {
"semver": "3.0.0",
"vm": "1.1.2",
"agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ public void testForeverInsideLoopInIfElse() throws IOException, ParsingException
Set<Issue> refactoredIssues = finder.check(refactoredProgram);
assertThat(refactoredIssues).isEmpty();
}

@Test
public void testForeverInLoopBlockBeforeUntil() throws IOException, ParsingException {
assertThatFinderReports(1, new ForeverInsideLoop(), "./src/test/fixtures/bugpattern/foreverInsideLoopBlockBeforeUntil.json");
}
}

0 comments on commit 90a91ed

Please sign in to comment.