Skip to content

Commit

Permalink
Fix scope for conditional resources (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenglol authored Apr 13, 2021
1 parent 65be2c6 commit aeadcc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,10 +1538,31 @@ public void Variable_loops_should_not_cause_infinite_recursion()
name: name
value: 'prefix-${i}-${name}-suffix'
}]
");

result.Should().NotHaveDiagnostics();
result.Template.Should().NotBeNull();
}

[TestMethod]
public void Test_Issue1883()
{
var result = CompilationHelper.Compile(@"
resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = if (true) {
name: 'myVM'
location: 'westus'
resource vmExt 'extensions' = {
name: 'myVMExtension'
location: vm.location
}
}
output vmExtName string = vm::vmExt.name
");

result.Should().NotHaveDiagnostics();
result.Template.Should().NotBeNull();
}
}
}
}
3 changes: 2 additions & 1 deletion src/Bicep.Core/Semantics/DeclarationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public override void VisitResourceDeclarationSyntax(ResourceDeclarationSyntax sy
// There may be additional scopes nested inside this between the resource declaration
// and the actual object body (for-loop). That's OK, in that case, this scope will
// be empty and we'll use the `for` scope for lookups.
var scope = new LocalScope(string.Empty, syntax, syntax.Value, ImmutableArray<DeclaredSymbol>.Empty, ImmutableArray<LocalScope>.Empty);
var bindingSyntax = syntax.Value is IfConditionSyntax ifConditionSyntax ? ifConditionSyntax.Body : syntax.Value;
var scope = new LocalScope(string.Empty, syntax, bindingSyntax, ImmutableArray<DeclaredSymbol>.Empty, ImmutableArray<LocalScope>.Empty);
this.PushScope(scope);

base.VisitResourceDeclarationSyntax(syntax);
Expand Down

0 comments on commit aeadcc1

Please sign in to comment.