Skip to content

Commit

Permalink
Block the use of interpolated string when a compile-time constant is …
Browse files Browse the repository at this point in the history
  • Loading branch information
shenglol authored Sep 1, 2023
1 parent 3c8021a commit 7394d7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5013,4 +5013,22 @@ public void Test_Issue10343()
var evaluated = TemplateEvaluator.Evaluate(result.Template);
evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo2"));
}

// https://github.com/Azure/bicep/issues/11292
[TestMethod]
public void Test_Issue11292()
{
var result = CompilationHelper.Compile(
Services.WithFeatureOverrides(new(SymbolicNameCodegenEnabled: true)),
("main.bicep", """
@description('foo${'bar'}')
param baz int
"""));

result.Template.Should().NotHaveValue();
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP032", DiagnosticLevel.Error, "The value must be a compile-time constant."),
});
}
}
9 changes: 9 additions & 0 deletions src/Bicep.Core/TypeSystem/CompileTimeConstantVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public override void VisitPropertyAccessSyntax(PropertyAccessSyntax syntax)
this.AppendError(syntax);
}

public override void VisitStringSyntax(StringSyntax syntax)
{
// Flag string interpolation since we don't support constant folding and constant propagation.
if (syntax.IsInterpolated())
{
this.AppendError(syntax);
}
}

public override void VisitTernaryOperationSyntax(TernaryOperationSyntax syntax)
{
this.AppendError(syntax);
Expand Down
5 changes: 0 additions & 5 deletions src/Bicep.LangServer/Extensions/DocumentUriExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using OmniSharp.Extensions.LanguageServer.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OmniSharp.Extensions.LanguageServer.Protocol
{
Expand Down

0 comments on commit 7394d7b

Please sign in to comment.