Skip to content

Commit 29d1293

Browse files
committed
multiple scope vars are now merge in twig "for" statements #463
1 parent e5995c1 commit 29d1293

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ public boolean value(PsiElement psiElement) {
343343
}
344344
}
345345

346-
globalVars.put(scopeVariable, new PsiVariable(types));
346+
// we already have same variable in scope, so merge types
347+
if(globalVars.containsKey(scopeVariable)) {
348+
globalVars.get(scopeVariable).getTypes().addAll(types);
349+
} else {
350+
globalVars.put(scopeVariable, new PsiVariable(types));
351+
}
347352

348353
}
349354

tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/variable/collector/FileDocVariableCollectorTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,20 @@ public void testVarChainArrayIteration() {
7979

8080
}
8181

82+
/**
83+
* @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigTypeResolveUtil#collectForArrayScopeVariables
84+
*/
85+
public void testThatDuplicateScopeVariablesAreMerged() {
86+
87+
assertCompletionContains(TwigFileType.INSTANCE, "" +
88+
"{# @var bars \\Bar\\FooClass #}\n" +
89+
"{% for bar in bars.fooBar %}\n" +
90+
" {# @var bar \\Bar\\FooClass #}\n" +
91+
" {{ bar.<caret> }}\n" +
92+
"{% endfor %}\n"
93+
, "fooBar"
94+
);
95+
96+
}
97+
8298
}

0 commit comments

Comments
 (0)